Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading byte array Textbox -> byte[]

Tags:

arrays

c#

nemerle

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 :(

Value=BitConverter.GetBytes(Int32.Parse(this.textBox3.Text.ToString()));
like image 889
cnd Avatar asked Aug 18 '26 04:08

cnd


1 Answers

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();
like image 108
Mark Byers Avatar answered Aug 21 '26 03:08

Mark Byers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!