2

How can I find common substrings of two strings in order to show changes/edit of a string?

So what I try to do is to compare an old version of a string:

string_old = "My name is pm730! How are you?"

with a new/edited version of the string:

string_new = "My name isn't pm730, it is pm740!"

Deleted substrings are not important. New substrings should be distinguished somehow, so that I could output it like this eventually:

My name isn't pm730 , it is pm740!

This task sounds easy but is more complicated than I thought. So my hope is that there is already an similar implementation available, but unfortunanly I can't find it...

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Pm740
  • 339
  • 2
  • 12
  • 3
    What you have tried by yourself so far? – ParthS007 Aug 19 '21 at 09:10
  • 2
    Are you asking how you can *find* common substrings or how to display bold text? – mkrieger1 Aug 19 '21 at 09:11
  • @mkrieger1 How to find common substings but bound on their location in order to eventually do somthing like the bold text. But the bold text isn't part of the question. – Pm740 Aug 19 '21 at 09:12
  • @ParthS007 I've already found all common substrings. I'm stuck on the part with the position bounding of the substrings. – Pm740 Aug 19 '21 at 09:18
  • Have you seen https://stackoverflow.com/questions/17904097/python-difference-between-two-strings? – mkrieger1 Aug 19 '21 at 09:19

0 Answers0