1、汉字转十六进制UNICODE编码字符串
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
/// <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)); //取出二进制编码内容 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; } |
2、 十六进制UNICODE编码字符串 转 汉字
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
/// <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; } |
以上这篇c# 实现获取汉字十六进制Unicode编码字符串的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。