详解c#实现获取汉字十六进制Unicode编码字符串的示例代码

黄舟
Release: 2017-03-27 11:54:17
Original
1646 people have browsed it

下面小编就为大家带来一篇c# 实现获取汉字十六进制Unicode编码字符串的实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

1、汉字转十六进制UNICODE编码字符串

 /// 
  /// ////
  /// 
  /// 
  /// 
  public string CharacterToCoding(string character)
  {
   string coding = "";

   for (int i = 0; i < character.Length; i++)
   {
    byte[] bytes = System.Text.Encoding.Unicode.GetBytes(character.Substring(i, 1));

    //取出二进制编码内容 
    string lowCode = System.Convert.ToString(bytes[0], 16);

    //取出低字节编码内容(两位16进制) 
    if (lowCode.Length == 1)
    {
     lowCode = "0" + lowCode;
    }

    string hightCode = System.Convert.ToString(bytes[1], 16);

    //取出高字节编码内容(两位16进制) 
    if (hightCode.Length == 1)
    {
     hightCode = "0" + hightCode;
    }

    coding += (hightCode + lowCode);

   }

   return coding;
  }
Copy after login

2、 十六进制UNICODE编码字符串 转 汉字

 /// 
  /// //
  /// 
  /// 
  /// 
  public string UnicodeToCharacter(string text)
  {
   byte[] arr = HexStringToByteArray(text);

   System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding();

   string str = converter.GetString(arr);


   return str;
  }
Copy after login

The above is the detailed content of 详解c#实现获取汉字十六进制Unicode编码字符串的示例代码. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!