I wrote the below in arduino code language (c or c++ ?)
And i got puzled, i'm not sure if this is a limitation from C or C++.
My function should split a text string and return word number x
In my function i need to clean a string variable, that resets its contend until X is reached
For readability X is called wordcount.
How do i clean the string Wordsample make it empty again ?
On a side note, if the word isnt found then this function should also return nothing
As the results are used to make other strings from.
String 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 = ''; // <== ERROR IS HERE
}
}
}
return result;}
On a side note, if possible I would like to keep use strings of any size, not fixed strings.