Remove a backslash character from a string in C#
I want to remove a backslash character from this string:
开发者_StackOverflow中文版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
Your string doesn't contain \
you dont need to remove them. \" is escape sequence that shows that in your string is " symbol(quotation mark)
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
test this code
String abc = result[0].Replace(@"\",@"");
String abc = result[0].Replace(@"\",string.Empty);
String abc = result[0].Replace(@"\\",@"");
String abc = result[0].Replace(@"\\",string.Empty).
精彩评论