String not replacing Single Quotes with required characters
string abc = "STA\'ASTEST";
if (abc.Contains("'"))
{
abc.Replace("'", "\\'");
}
String not replacing Single Quotes with required characters
string abc = "STA\'ASTEST";
if (abc.Contains("'"))
{
abc.Replace("'", "\\'");
}
You are doing the replace but not assigning the result to any variable.
I assume you want to assign the result to abc
string abc = "STA\'ASTEST";
if (abc.Contains("'"))
{
abc = abc.Replace("'", "\'");
}
It is also redundant to have the if (abc.Contains("'"))
because the Replace function will only replace if the expression to replace actually exists. So you can just write:
abc = abc.Replace("'", "\'");