从C#中的字符串中删除反斜杠字符

时间:2011-07-15 12:31:58

标签: c# .net string replace

我想从此字符串中删除反斜杠字符:

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}]}}]";

我试过了:

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

但没有任何效果。有人可以帮忙吗。

由于

4 个答案:

答案 0 :(得分:14)

您的字符串不包含\

答案 1 :(得分:2)

你不需要删除它们。 \“是转义序列,表明在你的字符串中是”符号(引号)

答案 2 :(得分:0)

更全面:

您的字符串不包含\字符。在变量声明中,它用于转义“字符,以便它可以放入字符串而不会导致字符串结束。”

如果在某处写出变量的值,你会发现没有\ characters

答案 3 :(得分:-1)

测试此代码

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