C#里几种Json字符串特殊字符的转义
标签:sse style string reg span 字符串 color ram pass
///
/// 替换部分字符串
///
/// 需要替换的字符串
///
public static string ReplaceString(string JsonString)
{
if (JsonString == null) { return JsonString; }
if (JsonString.Contains("\\"))
{
JsonString = JsonString.Replace("\\", "\\\\");
}
if (JsonString.Contains("\‘"))
{
JsonString = JsonString.Replace("\‘", "\\\‘");
}
if (JsonString.Contains("\""))
{
JsonString = JsonString.Replace("\"", "\\\"");
}
//去掉字符串的回车换行符
JsonString = Regex.Replace(JsonString, @"[\n\r]", "");
JsonString = JsonString.Trim();
return JsonString;
}
C#里几种Json字符串特殊字符的转义
标签:sse style string reg span 字符串 color ram pass
原文地址:http://www.cnblogs.com/wuyujie/p/7656488.html
评论