gdogg371
gdogg371

Reputation: 4122

Replacing a consecutive single and double quote using .replace?

I the following .replace statement I have an issue in that I am trying to replace a consecutive single and double quotation in a string:

mystring.replace(''"', '"')

That doesn't seem to work though, I suspect because I am wrapping the string to be replaced also in single quotes. How can I get around this?

Upvotes: 2

Views: 656

Answers (2)

Uma Kanth
Uma Kanth

Reputation: 5629

The second ' will be considered to be the closing quote, escape it using a \ to consider it in.

replace

mystring.replace(''"', '"')

with

mystring.replace('\'"', '"'); 

Upvotes: 2

Daniel
Daniel

Reputation: 42758

Escape the quote:

mystring.replace('\'"', '"')

Upvotes: 1

Related Questions