【发布时间】:2019-08-24 13:12:39
【问题描述】:
【问题讨论】:
-
我相信这不仅仅是任何字符串,而是来自某个地方的 Json 响应。所以这真的是你想要的吗?或者这只是一个快速修复
标签: asp.net asp.net-mvc-5
【问题讨论】:
标签: asp.net asp.net-mvc-5
您需要使用两个引号来转义要替换的引号,因此对于您的示例:
var MyString = DataString.Replace(@"""{", "{");
另请参阅How to include quotes in a string,了解在字符串中使用引号的替代方法。
【讨论】:
如果您期待JSON 数据,那么您真正需要的是JSON Parser。如果您只想将"{ 替换为{,则只需转义并替换如下字符串:
// Suppose the variable named str has a value of Hello"{ wrapped in double quotes
var strReplaced = str.Replace("\"{", "{");
Console.WriteLine($"strReplaced: {strReplaced}");
// This will result in strReplaced: Hello{
【讨论】: