I am currently attempting to remove unwanted characters from a string within my C# code.
The remove of the \ character, but it is removing too much. Below is a example of the string
“[{ \”attributes\” : { \”SR_ID\” : \”200003172375\”,
\”Fath_SR\” : \”EH0036\”, \”UPRN\” : \”100100024250\”,
\”Eastings\” : \”260376\”, \”Northings\” : \”358150\”,
\”Disgrifiad\” : \”Test\”, \”Date\” : \”25/01/2012\”,
\”Time\” : \”11:36\” }, \”geometry\” : { \”x\” :
270315, \”y\” : 345828 } }]”
I am attempting to remove the \ character, but leave the “. The only way I have been able to remove the \ is by using
sReturn = sReturn.Replace("\"",String.Empty);
But this removes the ” character.
I have tried the two attempts below, but for some reason it does not want to do as it told!
sReturn = sReturn.Replace(@"\",String.Empty);
sReturn = sReturn.Replace("\\",String.Empty);
Is there a way I could replace the \” with a “?
Assuming you really DO have
\"characters in your string and aren’t just looking at an escaped representation, you can simply do:If you want to unescape all possible types of escape sequences, use:
But as others have pointed out, you probably don’t really have these characters, and are just looking at a representation where it is shown in the escaped form, such as in visual studio debugger.