1、汉字转十六进制UNICODE编码字符串
代码如下 | 复制代码 |
/// /// //// /// /// /// publicstringCharacterToCoding(stringcharacter) { stringcoding ="";
for(inti = 0; i < character.Length; i++) { byte[] bytes = System.Text.Encoding.Unicode.GetBytes(character.Substring(i, 1));
//取出二进制编码内容 stringlowCode = System.Convert.ToString(bytes[0], 16);
//取出低字节编码内容(两位16进制) if(lowCode.Length == 1) { lowCode ="0"+ lowCode; }
stringhightCode = System.Convert.ToString(bytes[1], 16);
//取出高字节编码内容(两位16进制) if(hightCode.Length == 1) { hightCode ="0"+ hightCode; }
coding += (hightCode + lowCode);
}
returncoding; } |
2、 十六进制UNICODE编码字符串 转 汉字
代码如下 | 复制代码 |
/// /// // /// /// /// publicstringUnicodeToCharacter(stringtext) { byte[] arr = HexStringToByteArray(text);
System.Text.UnicodeEncoding converter =newSystem.Text.UnicodeEncoding();
stringstr = converter.GetString(arr);
returnstr; } |