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:
Code |
So I get:
Code
Button1
Button2
Button3
Button4Anyone who has some advice?
Thanks in advance,
JR

JR16 reputationPosted Oct 1, 2010, 2:50 PM EDT
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
JureRank #2,128 · 670 reputationPosted Oct 1, 2010, 2:56 PM EDT
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.