Zach
Zach

Reputation: 10139

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

Upvotes: 7

Views: 20424

Answers (4)

yakoui
yakoui

Reputation: 1

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).

Upvotes: -1

Jon Egerton
Jon Egerton

Reputation: 41569

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

Upvotes: 1

Renatas M.
Renatas M.

Reputation: 11820

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

Upvotes: 2

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56202

Your string doesn't contain \

Upvotes: 16

Related Questions