0

This is my string,

"Alexandra ""Alex""" 

I am trying to replace two adjacent double quotes with a /" so the result is something like this.

"Alexandra \"Alex\"" 

After this, I will append this string to an array. This looks very trivial, and I am able to do this with replace.

a = '"Alexandra ""Alex"""' x = a.replace('""', "\\\"") print x # prints "Alexandra \"Alex\"" res = [] res.append(x) print res # prints ['"Alexandra \\"Alex\\""'] 

When appending to another array it's escaping the forward slash again.

How can I remove the extra forward slash?

3
  • 2
    That's just the way it formats printing the list. The string isn't modified when it is appended. Also, that's a backslash. Commented Jun 6, 2017 at 5:46
  • @AlexanderO'Mara So how can i replace the double quotes to /" then ? Commented Jun 6, 2017 at 5:50
  • @Ilja Everilä Can you remove the duplicate, the question is now more on how to replace the double quote with a /" Commented Jun 6, 2017 at 5:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.