想要将包含ASCII字符串的字符串转换为文本,我似乎只能找到从Byte []转换的System.Text.ASCIIEncoding.ASCII.GetString但在这种情况下我希望能够做到这一点从一个字符串.
its a string containing ASCII hex: For example : ASCI = 47726168616D would equal Graham
这有什么内置功能吗?感谢帮助,谢谢.
private static string GetStringFromAsciiHex(String input)
{
if (input.Length % 2 != 0)
throw new ArgumentException("input");
byte[] bytes = new byte[input.Length / 2];
for (int i = 0; i < input.Length; i += 2)
{
// Split the string into two-bytes strings which represent a hexadecimal value, and convert each value to a byte
String hex = input.Substring(i, 2);
bytes[i/2] = Convert.ToByte(hex, 16);
}
return System.Text.ASCIIEncoding.ASCII.GetString(bytes);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11414 次 |
| 最近记录: |