Buenos dias,
just implemented a String split function. Since I see there's a lot of convenience functionality in String, but no split, maybe you want to include this so not everyone has to do this tedious index-fiddling again ;)
// declaration (default param)
std::vector<String> splitString(const String& input,
const char delimiter,
bool skipEmpty=false);
// implementation
std::vector<String> splitString(const String& input,
const char delimiter,
bool skipEmpty) {
std::vector<String> outVector;
int lastIndex = 0;
for(int index = 0 ; index < input.length() ; ++index) {
String substring;
if(input[index] == delimiter) {
substring = input.substring(lastIndex, index);
lastIndex = index+1;
if(skipEmpty && substring == "") {}
else
outVector.push_back(substring);
}
if(index+1 >= input.length()) {
substring = input.substring(lastIndex, index+1);
if(skipEmpty && substring == "") {}
else
outVector.push_back(substring);
}
}
return outVector;
}
For performance reasons you might want to switch to the getCharPointer interface, for me it's fine like this.
Best, Patric
