Nov-25-2017, 09:25 PM
For example, I want to change this string:
Quote:'abc "this that" xyz'
with this string:
Quote:'abc ____ ____ xyz'
There will only be one pair of double quotes in the string.
I think I know how to find the positions of the double quote delimiters, and how to replace an alpha character with an underscore. But I am not about how to put it into a loop.
import re s = 'abc "this that" xyz' d = '"' # find and print order of " delimiter print ( [pos for pos, char in enumerate(s) if char == d] ) # replace t = s.replace(s[i], '_')