开发者

Reading byte array Textbox -> byte[]

开发者 https://www.devze.com 2022-12-19 10:13 出处:网络
I\'ve got Textbox with a string like 89 3d 2c c0 7f 00 How to store it to Byte[] (byte array) variable ?

I've got Textbox with a string like 89 3d 2c c0 7f 00

How to store it to Byte[] (byte array) variable ?

Now I can read only one dec value :(开发者_JS百科

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


Use textBox3.Text.Split() to get an array of strings, each of length 2.

Then use byte.Parse(part, NumberStyles.HexNumber) in a loop to convert each part from hexadecimal to an integer.

Using LINQ it can be written like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号