Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a backslash character from a string in C#

I want to remove a backslash character from this string:

String result = "[{\"venues\":{\"venueId\":1,\"name\":\"First Venue\","
            + "\"telephone\":\"jkljl\",\"description\":\"Edited Description\","
            + "\"address\":\"jlkjlj\",\"city\":\"lkjl\",\"postcode\":\"M221TX\","
            + "\"image\":z\"abcImage007.jpg\",\"latitude\":53.37655,\"longitude\":-2.27418,\"deleted\":0,"
            + "\"events\":[{\"eventId\":3,\"name\":\"Test Event\",\"description\":\"Test Event Description\",\"date\":\"24/07/2011\",\"startTime\":\"11:11\",\"venueId\":0,\"deleted\":1},"
            + "{\"eventId\":3,\"name\":\"Test Event\",\"description\":\"Test Event Description\",\"date\":\"25/07/2011\",\"startTime\":\"11:11\",\"venueId\":0,\"deleted\":1}]}}]";

I have tried:

String abc = result.Replace(@"\",@"");
String abc = result.Replace(@"\",string.Empty);
String abc = result.Replace(@"\\",@"");
String abc = result.Replace(@"\\",string.Empty);

But nothing is working. Could someone help please.

Thanks

like image 650
Zach Avatar asked Jul 15 '11 12:07

Zach


3 Answers

Your string doesn't contain \

like image 197
Kirill Polishchuk Avatar answered Nov 15 '22 05:11

Kirill Polishchuk


you dont need to remove them. \" is escape sequence that shows that in your string is " symbol(quotation mark)

like image 21
Renatas M. Avatar answered Nov 15 '22 05:11

Renatas M.


More fully:

Your string doesn't contain the \ character. In the variable declaration it is used to escape the " character so that it can be put into the string without causing the end of the string to occur.

If write out the value of the variable somewhere you'll find there are no \ characters

like image 37
Jon Egerton Avatar answered Nov 15 '22 04:11

Jon Egerton