在c#中从字符串中删除反斜杠字符

本文关键字:字符 字符串 删除 | 更新日期: 2023-09-27 18:02:06

我想从这个字符串中删除一个反斜杠字符:

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 try:

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

但是什么都不起作用。有人能帮帮忙吗?

谢谢

在c#中从字符串中删除反斜杠字符

您的字符串不包含'

你不需要删除它们。'"是转义序列,表示在字符串中是" symbol(引号)

详细说明:

您的字符串不包含'字符。在变量声明中,它用于转义"字符,以便将其放入字符串中而不会导致字符串结束。

如果把变量的值写在某个地方,你会发现没有'字符

测试此代码

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