c implementation to get the Chinese character hexadecimal Unicode encoding string instance

  • 2020-05-12 02:58:47
  • OfStack

1, Chinese characters to 106 UNICODE encoding string


 /// <summary>
  /// ////
  /// </summary>
  /// <param name="character"></param>
  /// <returns></returns>
  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));

    // Take out the 2 Base code content  
    string lowCode = System.Convert.ToString(bytes[0], 16);

    // Fetch the low-byte encoded content (two bits) 16 Hexadecimal)  
    if (lowCode.Length == 1)
    {
     lowCode = "0" + lowCode;
    }

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

    // Fetch the high-byte encoded content (two bits) 16 Hexadecimal)  
    if (hightCode.Length == 1)
    {
     hightCode = "0" + hightCode;
    }

    coding += (hightCode + lowCode);

   }

   return coding;
  }

2. Base 106 UNICODE encodes strings into Chinese characters


 /// <summary>
  /// //
  /// </summary>
  /// <param name="text"></param>
  /// <returns></returns>
  public string UnicodeToCharacter(string text)
  {
   byte[] arr = HexStringToByteArray(text);

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

   string str = converter.GetString(arr);


   return str;
  }



Related articles: