国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

json中含有Unicode的處理辦法 C#

原創(chuàng) 2016-11-10 14:45:04 643
摘要:public static class StringExtension   {           #region unicode 字符轉(zhuǎn)義       /// 
public static class StringExtension  
{      
    #region unicode 字符轉(zhuǎn)義  
    /// <summary>  
    /// 轉(zhuǎn)換輸入字符串中的任何轉(zhuǎn)義字符。如:Unicode 的中文 \u8be5  
    /// </summary>  
    /// <param name="str"></param>  
    /// <returns></returns>  
    public static string UnicodeDencode(this string str)  
    {  
        if (string.IsNullOrWhiteSpace(str))  
            return str;  
        return Regex.Unescape(str);  
    }  
    /// <summary>  
    /// 將字符串進行 unicode 編碼  
    /// </summary>  
    /// <param name="str"></param>  
    /// <returns></returns>  
    public static string UnicodeEncode(this string str)  
    {  
        if (string.IsNullOrWhiteSpace(str))  
            return str;  
        StringBuilder strResult = new StringBuilder();  
        if (!string.IsNullOrEmpty(str))  
        {  
            for (int i = 0; i < str.Length; i++)  
            {  
                strResult.Append("\\u");  
                strResult.Append(((int)str[i]).ToString("x4"));  
            }  
        }  
        return strResult.ToString();  
    }  
    #endregion  
}
發(fā)布手記

熱門詞條