Home:ALL Converter>How to empty a string in Arduino c language

How to empty a string in Arduino c language

Ask Time:2014-03-24T07:55:45         Author:user613326

Json Formatter

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.

Author:user613326,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/22598795/how-to-empty-a-string-in-arduino-c-language
yy