I want to replace \ with " symbol using C# code.Here i am writing code for it.
string str=jsonstringdata.Replace("\"",""");
But it showing error obviously.
I want to replace \ with " symbol using C# code.Here i am writing code for it.
string str=jsonstringdata.Replace("\"",""");
But it showing error obviously.
Use either single-quoted characters, @verbatim strings, or properly escape the characters:
str.Replace('\\', '"')
str.Replace(@"\", @"""")
str.Replace("\\", "\"")
Explanations:
'
. The same backslash-escape rules from literal strings apply to literal characters, except that you can specify a double-quote directly (i.e. '"'
instead of '\"'
).@""""
is a string containing a single double-quote character, similarly @"foo""bar"
is a string with a single double-quote between "foo" and "bar".this should do it - need to escape the correct characters.
string str = jsonstringdata.Replace("\\","\"");
You need to handle escape sequences correctly. Use a \\ for finding \ and \" for replacing each \ with ". See the following link http://msdn.microsoft.com/en-us/library/aa691087(v=vs.71).aspx
string input = @"\a\\\\";
char replaceble = '\\';
char replacingChar = '\"';
var output = input.Replace(replaceble, replacingChar);
You need to escape the slash and quote characters.
var jsonStringData = "{ Hello\\World }";
string str = jsonStringData.Replace("\\", "\"");
// output of str = { Hello"World }