Replace special qoutes with normal

1k views Asked by At

In VB.NET how do I replace special opening and closing double quotes (“ and ”) with ASCII quotes (").

Ive tried

s = s.replace("“", """")

but it seems that Visual Studio consider the “ quote in my code to be a normal quote leaving me with an invalid statement.

2

There are 2 answers

0
Adriano Repetti On BEST ANSWER

Unfortunately VB.NET doesn't support escape sequences but you can use ChrW() to specify code point:

s = s.Replace(ChrW(&H201C), """")

That's for , code for is &H201D. Note that using code points you're free to search & replace any Unicode character (not just what VB.NET has an escape for - like ").

For complete list see: http://unicode-table.com/en/

0
israel altar On

If you want to use a quotation mark inside a string, VB doesn’t know whether the quotation mark is supposed to end the string or not. In C#, this would be fixed by escaping the quotation mark, i.e. in place of """ you’d write "\"". In VB, the same is done by doubling the quotation mark, i.e. """".

Back to your curly quote. The same as for straight quotes applies according to the VB language specification (¶1.6.4). So to write a curly quote in code, try the following:

s = Replace(s , "““", "“")

a second way: s = Replace(s , ChrW(&H201C), "“")