How to stream data entered by the user in text box into int array? Let's say, that I've got a window with 2 text boxes and buttons and buffer, that is not visible in interface.
I want data from textbox1 (for example CAT) to be saved into int buffer[255] after clicking button1. Then, after clicking button2, 'CAT' should appear in textbox2 and being deleting from buffer.
It should be like:
int buffer[255]={0};
//user entered 'CAT' in textbox1
//clicking button1
//now:
buffer[0]=[67]; //67 = 'C' in ASCII
buffer[1]=[65];
buffer[2]=[84];
//clicking button2
//in read-only textbox2 'CAT' appears
//now:
buffer[]={0};
I guess there will be need some conversion while displaying word in textbox2 (for loop with System.Convert.ToChar(buffer[i])), but what puzzles me most is how to save text from textbox1 into buffer.
Ok, thx for responses, now I need to make my button work, but don't know why, I've got now this method:
public int saveToBuffer(string text)
{
string txt = text;
int[] receivedBuffer = new int[255];
int count = 0;
//int i = 0;
foreach(char c in txt)
{
receivedBuffer[count] = c;
count++;
}
return receivedBuffer[255];
}
Which returns text from textbox1 to array receivedBuffer. I also got this button:
private void saveToBufferButton_Click(object sender, EventArgs e)
{
}
and I don't know what to put beetwen {} to make it work.
textbox1.Texttill thetextbox1.Text.Lengthand get each char into buffer index.