Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string replace single quote to double quote in C#

Tags:

string

c#

replace

How can I replace a single quote (') with a double quote (") in a string in C#?

like image 810
kst Avatar asked Mar 04 '11 03:03

kst


People also ask

How do you replace single quotes with double quotes in string?

Use the String. replace() method to replace double with single quotes, e.g. const replaced = str. replace(/"/g, "'"); . The replace method will return a new string where all occurrences of double quotes are replaced with single quotes.

How do you replace a single quote in a string?

Use the String. replace() method to replace single with double quotes, e.g. const replaced = str. replace(/'/g, " ); . The replace method will return a new string where all occurrences of single quotes are replaced with double quotes.

How do you declare a double quote in a string?

To place quotation marks in a string in your code In Visual Basic, insert two quotation marks in a row as an embedded quotation mark. In Visual C# and Visual C++, insert the escape sequence \" as an embedded quotation mark.


2 Answers

You need to use the correct escape sequence for the quotes symbol, you can find more information about escape sequencies here.

String stringWithSingleQuotes= "src='http://...';"; String withDoubleQuotes = stringWithSingleQuotes.Replace("'","\""); 
like image 193
Bala R Avatar answered Oct 05 '22 23:10

Bala R


var abc = "hello the're"; abc = abc.Replace("'","\""); 
like image 29
Rob Avatar answered Oct 05 '22 23:10

Rob