The following small series for everyone to bring a C # implementation to get the Chinese character hexadecimal Unicode encoded string instance. Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.
1. Chinese character to hexadecimal Unicode encoded 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)); Remove binary encoded content string lowcode = System.Convert.ToString (bytes[0], +); Remove the low-byte encoded content (two-bit 16-binary) if (lowcode.length = = 1) { Lowcode = "0" + Lowcode; } String hightcode = System.Convert.ToString (bytes[1], +); Remove the high-byte encoded content (two-bit 16-binary) if (hightcode.length = = 1) { Hightcode = "0" + Hightcode; } Coding + = (Hightcode + lowcode); } return coding; }
2. Hexadecimal Unicode encoded string to Kanji
<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; }