I wrote the code below to return a word from a string, i call it substring, as well a word is a revorved name.
The problem i face with this code, that with arduino c++
I cannt use empty strings,
WordSampleN = ''; //seams not allowed
or is there some trick for it ?.
My goal is to have a function that takes the nth (wordcount number) as a word from a string
There might be another problem in this code, but well i'm at first stuck by the assigning an empty to a string.
As i am not sure if assigning it null would solve this, how to deal with empty strings in arduino's c++ ?
int GetSubString (String A,int Wordcount) //for readability start counting B from 1
{ int CounterX;
String WordSampleN;
String result ;
for (int i = 0; i < A.length(); i++)
{ // split string
WordSampleN = WordSampleN + A[i];
if ((A[i] == ' ') || (A[i] =='\n'))
{ CounterX++;
if (CounterX == Wordcount)
{ result = WordSampleN;
}
if (CounterX <> WordCount)
{ WordSampleN = '';
}
}
}
return result;
}