eg ‘“Hello Word” = "hello world";’, '"Hello=Word" = "Hello=Word"',find the middle of the "=" position by python. I try this
>>>line = '"Hello=Word" = "Hello=Word"'
>>>index = line.index("=")
>>> index
6
I expect it return 13
eg ‘“Hello Word” = "hello world";’, '"Hello=Word" = "Hello=Word"',find the middle of the "=" position by python. I try this
>>>line = '"Hello=Word" = "Hello=Word"'
>>>index = line.index("=")
>>> index
6
I expect it return 13
Probably a case for using regexes.
import re
re.search(r'^".*".*(=).*".*"$', line).start(1)
This assumes the string is of the form you specified, with double-quote "
delimited strings on either side of an =
.
Actually, you can also look on all occurrences of =
in string via enumerate(line)
. It returns you an enumerate
object, which is iterable and contains tuples with format (index, item). So, that can be used like this:
>>> occurrences = [x[0] for x in enumerate(line) if x[1] == '=']
>>> occurrences
[6, 13, 21]
Now you should pick that index which you need.