Issue
I have a long String: s1= "I am asking a question related to python String" and I have a substring: s2 = "related to python String" I am looking for the result "I am asking a question" which is (s1-s2) any efficient way to do it?
Solution
You can use .replace()
.
sliced_string = long_string.replace(short_string, '')
Keep in mind it will remove all the occurences of the short_string.
Use replace(short_string, '', 1)
to remove only one occurence.
Answered By - Random_Pythoneer59
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.