最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
c# 实现获取汉字十六进制Unicode编码字符串的实例
时间:2017-03-03 编辑:简简单单 来源:一聚教程网
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; } |
-
上一个: C# 最齐全的上传图片方法
相关文章
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10
- .NET使用YARP通过编码方式配置域名转发实现反向代理教程 10-10