kst
kst

Reputation: 1518

string replace single quote to double quote in C#

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

Upvotes: 37

Views: 96090

Answers (3)

Bala R
Bala R

Reputation: 109027

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

Upvotes: 55

Shubhangi kandhare
Shubhangi kandhare

Reputation: 19

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

Upvotes: 1

Rob
Rob

Reputation: 27377

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

Upvotes: 8

Related Questions