string ascii = "53573a432e302e31";
List<byte> buffer = new List<byte>(); //类似数组,但可以存储任何类型数据
for (int i = 0; i < ascii.Length; i += 2)
{
buffer.Add(value); // 添加到buffer数组中
}
string str = System.Text.Encoding.ASCII.GetString(buffer.ToArray());
List<byte> buffer = new List<byte>(); //类似数组,但可以存储任何类型数据
for (int i = 0; i < ascii.Length; i += 2)
{
string temp = ascii.Substring(i, 2); // 取其中的两位,即53、57、3a等
byte value = System.Convert.ToByte(temp, 16); //把字符转换成0x53, 0x57, 0x3a等buffer.Add(value); // 添加到buffer数组中
}
string str = System.Text.Encoding.ASCII.GetString(buffer.ToArray());
本文介绍了一种将ASCII字符串转换为字节序列的方法。通过遍历字符串并使用16进制转换,将每两个字符视为一个字节值,最终形成一个包含所有字节的列表。该过程适用于需要进行ASCII编码与字节数据相互转换的应用场景。
3860

被折叠的 条评论
为什么被折叠?



