Where does the string come from? If your reading it character-by-character from a stream, I would say your best bet s to parse it on the fly. If you have to parse the string in memory, have a look at strtok()
You can google for zillions of examples. Your code would give ("\b\r\n") as delimiters, then look at the strings found. The ones that aren't "" are what you are looking for.
The string comes throu the usb-port from a computer.
So I can look for one letter at the time.
The porblem that I have not solved is how I shall know how many LF's I got and then get the letters after that,
You can have the code discard those delimiters. it should be as simple as
Example.
char c = Serial.read();
if( c != '\b' || c != '\r' || c != '\n') // check if incoming char is NOT any of the 3 delimiters
{
// not a delimiter, store the char in an array
}
Now if there is a distinct pattern to the delimiters as to what comes in first and last, then you can have the code split the chars into there own index in the array, instead of them all together.
That only check what letter that I received.
There are no pattern how the string is received so I need to count the LFs and after I count them I need to store that parameter.
Then do a new count on LFs for store in another parameter. Thats my problem, hox to count and then store the letters after counting.
if( c != '\b' || c != '\r' || c != '\n') // check if incoming char is NOT any of the 3 delimiters
{
// not a delimiter, store the char in an array
}
I think this test need && rather than || in each case.
It looks like marks the end of each sequence so I suggest you use that as an end-marker and save everything up to that in a char array and then parse the array for the piece you want. The code in Chapter 8 of this Demo shows how to use an end-marker.
// a the top of the code, above setup()
char data[10][10]; // declared globally
byte i = 0, j = 0, idx = 0;
//within the loop()
char c = Serial.read();
if( c != '\b' || c != '\r' || c != '\n') // check if incoming char is NOT any of the 3 delimiters
{
data[i] [j]= c;
j++;
}
else if(c == '\n') // if the incoming char is '\n', start a counter until another(different) delimiter is found
{
j = 0;
idx++;
}
else if(c == '\b' || c == '\r') // if the char is '\b' or '\r', then change the array index based on the counter
{
i = idx;
idx=0;
}
@Robin, I was thinking that too, but I can't test it on my end to be sure. If it doesn't work as it is now, then he can change it to use &&
It looks like marks the end of each sequence
If that is true, then it will make the code a little easier.
// a the top of the code, above setup()
char data[10][10]; // declared globally
byte i = 0, j = 0;
//within the loop()
char c = Serial.read();
if( c != '\b' || c != '\r' || c != '\n') // check if incoming char is NOT any of the 3 delimiters
{
data[i] [j]= c;
j++;
}
else if(c == '\r') // if the incoming char is '\r', increment the index
{
j = 0;
i++;
}
Note: nothing in the string indicates when the code is getting new strings to split, so i++ will continue to increment = not good.