我可以在C#中使用控制字符吗?

时间:2019-05-15 18:36:07

标签: c# char hex ascii

我试图将控制字符附加到字符串的开头,然后将该字符串转换为字节数组。我知道我要附加的字符的十六进制代码为:0x01、0x0e,0x02。可以将它们写为字符然后进行转换吗?

这就是我的想法:

string myString = "Hello World!";

//I want to use characters here instead of the hex codes
string myHex = "0x01 0x0e 0x02";

string myCombinedString = myHex + myString;

Byte[] myByteArray = Encoding.ASCII.GetBytes(myCombinedString);

预期输出:

010e0248656c6c6f20576f726c6421

0 个答案:

没有答案