My name is JR and I am writing a small application that I use to communicate with my Arduino board (www.arduino.cc). Communication is done using serial commands.
I want to split a string based on another string. For example:
|
So I get:
I've tried the split function but this allow me to split based on chars and not a specific sequence of chars (string).Button1Button2Button3Button4
Anyone who has some advice?
Thanks in advance,
JR
JurePosted Oct 1, 2010, 6:56 PM
string SerialIn = "Button1[e]Button2[e]Button3[e]Button4[e]";
string Footer = "[e]";
string[] splitted = SerialIn.Split(new string[] { Footer },
StringSplitOptions.RemoveEmptyEntries);
foreach (string str in splitted)
{
Console.WriteLine(str);
}
Console.ReadKey();
You have probably just missed an overload (there are 6 of them).
EDIT: Glad you solved it.
JRPosted Oct 1, 2010, 6:50 PM
BufferIn = comport.ReadExisting();
string[] DataArray = BufferIn.Split(new string[] { TxtReceiveHeader.Text }, StringSplitOptions.RemoveEmptyEntries);
if (DataArray.Length > 0)
for (int i = 0; i < DataArray.Length-1; i++)
{
Debug.WriteLine(DataArray[i]);
}
Cheers