如何将功能键F3转换为字节数组?

时间:2017-10-16 07:00:09

标签: c#

如何将功能键F3转换为C#中的字节数组?我们尝试了下面的代码,但它没有工作。

Secondcommand = "\x1bOR"; //F3
byte[] Bcommand_sec3 = System.Text.Encoding.ASCII.GetBytes(Secondcommand);
Obj_StreamOutput.Write(Bcommand_sec3, 0,Bcommand_sec3.Length);

1 个答案:

答案 0 :(得分:0)

尝试以下

public static byte[] StrToByteArray(string hexValue) {
    return Enumerable.Range(0, hexValue.Length)
                 .Where(x => x % 2 == 0)
                 .Select(x => Convert.ToByte(hexValue.Substring(x, 2), 16))
                 .ToArray();
}