随笔 - 83,  文章 - 6,  评论 - 20,  阅读 - 10万

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);
}
复制代码
posted on   £冷☆月№  阅读(269)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示