2

I am stuck with converting textbox string value to byte array. For ex;

Textbox1.text="ABC";
converting to byte array as
byte[] array1;
array1[0]=65;
array1[1]=66;
array1[2]=67;

Then I want to write all array1 to Textbox2 as

Textbox2=656667

Shortly, Input is "ABC" Ouput is "656667". I am working with below codes it gives error at

int value = Int32.Parse(arrText[i], System.Globalization.NumberStyles.Number);

sample code

string text = textBox1.Text + " ";// .Text + " ";
text.Trim();
string[] arrText = text.Split(' ');
byte[] data = new byte[arrText.Length];
for (int i = 0; i < arrText.Length; i++)
{
    if (arrText[i] != "")
    {
        int value = Int32.Parse(arrText[i],
            System.Globalization.NumberStyles.Number);  //gives error
        data[i] = (byte)Convert.ToByte(value);
    }
}

for (int i = 0; i < arrText.Length; i++)
{
    textBox2.Text += data[i].ToString();
}
9
  • 2
    stackoverflow.com/questions/472906/… Commented Sep 9, 2014 at 12:21
  • Could you show me my error why it is happening? Commented Sep 9, 2014 at 12:35
  • What can I write in order to "int value = Int32.Parse(arrText[i], System.Globalization.NumberStyles.Number);" Commented Sep 9, 2014 at 12:38
  • What error are you getting? Have you run it in the debugger to see what the actual inputs are? Is arrText[i] a valid number? Commented Sep 9, 2014 at 12:39
  • What is the error you get ? Commented Sep 9, 2014 at 12:40

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.