简体   繁体   English

读取字节数组Textbox - > byte []

[英]Reading byte array Textbox -> byte[]

I've got Textbox with a string like 89 3d 2c c0 7f 00 我有一个字符串,如89 3d 2c c0 7f 00

How to store it to Byte[] (byte array) variable ? 如何将它存储到Byte [](字节数组)变量?

Now I can read only one dec value :( 现在我只能读取一个十进制值:(

Value=BitConverter.GetBytes(Int32.Parse(this.textBox3.Text.ToString()));

Use textBox3.Text.Split() to get an array of strings, each of length 2. 使用textBox3.Text.Split()获取长度为2的字符串数组。

Then use byte.Parse(part, NumberStyles.HexNumber) in a loop to convert each part from hexadecimal to an integer. 然后在循环中使用byte.Parse(part, NumberStyles.HexNumber)将每个部分从十六进制转换为整数。

Using LINQ it can be written like this: 使用LINQ可以这样写:

byte[] result = textBox3.Text.Split(' ')
    .Select(part => byte.Parse(part, System.Globalization.NumberStyles.HexNumber))
    .ToArray();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM