Reputation: 559
I´m little new to C# and i got some questions here:
I want to send my age in hex codes by serial port to a device that my pc is attached with. I have those codes but i have to read from textBox the age inputed.
For example: at textBox I enter my age (24) and each number has a hex code. So how do i read from textBox each number? I think that is what i have to do, I read number 2, send hex code, then read the second number and send hex code. Have I been clear?
EDIT: Just showing u guys my code after i got awnsered. Thanks all :)
private void btnConfirmaIdade_Click(object sender, EventArgs e)
{
string allValue = mtxbIdade.Text;
foreach (char c in allValue)
{
MandaIndadeSerial(c);
}
}
public void MandaIndadeSerial(char c)
{
switch (c)
{
case '1':
EnviarComando("0232363b3bde03");// send hexa code to device by serial
break;
Upvotes: 2
Views: 197
Reputation: 6265
foreach(char c in TextBox.Text)
{
// TODO: send current number. Cast to string if needed: (string)c
}
This code iterates through all numbers/characters in TextBox, left to right, and allows you to process/send them separately.
Upvotes: 5
Reputation: 869
string numbers = new string[2];
numbers[0] = textbox.Text.Substring(0,1); //first character in textbox
numbers[1] = textbox.Text.Substring(1,1); //second character
Upvotes: 0