zoukankan      html  css  js  c++  java
  • 将汉字以utf8方式编码及解码

    编码:
    using System.Text;

    byte[] buffer = Encoding.GetEncoding("utf-8").GetBytes("中国");
    string str = "";

    foreach (byte b in buffer) str += string.Format("%{0:X}", b);


    解码:
    public static string Decode(string str)
      
         {
             
      string[] strs = str.Split('%');
        
           List<byte> list = new List<byte>();
          
         for (int i = 0; i < strs.Length; i++)
           
        {
                 
      if (strs[i] == "") continue;
        
         int a = Int32.Parse(strs[i].ToLower(), System.Globalization.NumberStyles.AllowHexSpecifier);
      //将十六进制转换成十进制  
               list.Add((byte)a);
           
        }
            
       return CharsToString(System.Text.Encoding.UTF8.GetChars(list.ToArray()));
       
        }




  • 相关阅读:
    NumPy线性代数
    NumPy矩阵库
    NumPy副本和视图
    NumPy字节交换
    NumPy排序、搜索和计数函数
    NumPy统计函数
    NumPy算数运算
    NumPy数学算数函数
    NumPy
    dp 动规 最佳加法表达式
  • 原文地址:https://www.cnblogs.com/weihongli/p/3040212.html
Copyright © 2011-2022 走看看