zoukankan      html  css  js  c++  java
  • 将Unicode字符串转换为普通文字

         Json传输中文时为了防止乱码,通常我们会进行Unicode编码 ,如{userID:"001",nickname:"\u65e0\u8bed\u68a6" }
        下面的代码,将能完成Unicode的与普通字符的转换功能,函数是在网上找的,做个记号

    private string U2CnCode(string str)
    {
        Match m;
        Regex r 
    = new Regex("(?<code>\\\\u[a-z0-9]{4})", RegexOptions.IgnoreCase);
        
    for (m = r.Match(str); m.Success; m = m.NextMatch())
        {
            
    string strValue = m.Result("${code}");   //代码
            int CharNum = Int32.Parse(strValue.Substring(24), System.Globalization.NumberStyles.HexNumber);
            
    string ch = string.Format("{0}", (char)CharNum);
            str 
    = str.Replace(strValue, ch);
        }
        
    return str;
    }
  • 相关阅读:
    struts2 DMI
    MFC添加背景图片
    c++ 副本构造器
    climits
    Qt中的qreal
    Http概述(一)
    重构学习-重构原则
    QDir的mkdir和mkpath区别
    Qt学习笔记网络(一)
    Qt5 新特性
  • 原文地址:https://www.cnblogs.com/Pharaoh/p/1490159.html
Copyright © 2011-2022 走看看