Reputation: 127
I am having a text string- "The class also contains a string for the collection’s title and a scalar Boolean variable indicating whether the collection is currently editable."
Here, I'm trying to fetch the index of the sub-string "collection's" but getting the below error. ValueError: substring not found
I understand that the apostrophe in the sub-string in the actual text is in different font. So, is there any way where we can bypass difference in the font.
txt = "The class also contains a string for the collection’s title and a scalar Boolean variable indicating whether the collection is currently editable."
print(txt.index("collection's"))
Expected is to have the index of the sub-string- "collection's"
actual result is: ValueError: substring not foundenter code here
Upvotes: 0
Views: 68
Reputation: 20490
Just make sure your text and the string you are looking for use the same form of apostrophe '
txt = "The class also contains a string for the collection's title and a scalar" \
"Boolean variable indicating whether the collection is currently editable."
print(txt.index("collection's"))
#41
Upvotes: 0