string replace single quote to double quote in C#

2019-04-03 04:38发布

问题:

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

回答1:

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("'","\"");


回答2:

var abc = "hello the're";
abc = abc.Replace("'","\"");


回答3:

string str;
str=strtext.Replace('"','\'');