hi guys i m beginner in c# and i wand a help with strings!
i have search for help 3months ago but i start agen the project now
i have design a micro controller project that sen in serial port some
character strings that contains at the beginning three characters!
the characters is two dashhes ## with a number inside
e.g. #1#
the micro controller part working OK bun th c# software that read this data i have problem with the strings!
i recive data with the
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
//RxString = serialPort1.ReadExisting();
RxString = serialPort1.ReadLine();
this.Invoke(new EventHandler(DisplayText));
}
and display with
private void DisplayText(object sender, EventArgs e)
{
textBox1.AppendText(RxString);
}
this works but i wand when the string detect #1# to display the
rest characters of string in first line and when detects #2# to display
in second line!
string format example
#1#vdfkm fskjf jklfkgj #2#kfldjdfgbkdj #1#mlkfjgvfdjgdf...........
can someone help me on this
thanks and sorry for my bad english
Loading
AlanPosted Oct 22, 2008, 4:52 PM
If you mean that you want the textbox display to be like this:
vdfkm fskjf jklfkgjmlkfjgvfdjgdf
kfldjdfgbkdj
then try the following:
RxString = serialPort1.ReadLine();
if (RxString.Length > 3 && RxString[0] == '#' && RxString[2] == '#')
{
lineNum = (int)RxString[1] - 48;
lines[lineNum - 1] += RxString.Substring(3);
}
else
{
// append to 'current' line
lines[lineNum - 1] += RxString;
}
this.Invoke(new EventHandler(DisplayText));
// add some fields
private string[] lines = new string[9] { "", "", "", "", "", "", "", "", "" };
private int lineNum = -1;
private void DisplayText(object sender, EventArgs e)
{
textBox1.Lines = lines;
}