1.字符串中的英文双引号变成中文双引号
/// <summary> /// 替换字符串中的英文双引号为中文双引号 /// </summary> /// <param name="str"></param> /// <returns></returns> public static string ReplaceYinHaoEnToCn(string str) { string newStr = ""; string[] array = str.Split('"'); for (int i = 1; i <= array.Length; i++) { if (i % 2 == 0) { newStr += array[i - 1] + "”"; } else { newStr += array[i - 1] + "“"; } } return newStr.Substring(0, newStr.Length - 1); }
2.json字符串属性值中的英文双引号变成中文双引号
/// <summary> /// json字符串将属性值中的英文双引号变成中文双引号 /// </summary> /// <param name="strJson">json字符串</param> /// <returns></returns> public string JsonReplaceSign(string strJson) { //获取每个字符 char[] temp = strJson.ToCharArray(); //获取字符数组长度 int n = temp.Length; //循环整个字符数组 for (int i = 0; i < n; i++) { //查找json属性值(:+" ) if (temp[i] == ':' && temp[i+1] == '"') { //循环属性值内的字符(:+2 推算到value值) for (int j = i+2; j < n; j++) { //判断是否是英文双引号 if (temp[j] == '"') { //排除json属性的双引号 if (temp[j+1] != ',' && temp[j+1] != '}') { //替换成中文双引号 temp[j] = '”'; } else if (temp[j+1] == ',' || temp[j+1] == '}') { break; } } else if (true) { // 要过虑其他字符,继续添加判断就可以 } } } } return new String(temp); }
分类:
C#
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构