Eigentlich nicht.
Das ist ja eine eigene split-Funktion (siehe link, drüber) die was in einen Array läd, ich meinte eher sowas:
string str = "text1; text2bla; text3blub; ; text5texttexttext";
vector<string> tokens;
Tokenize(str, tokens, ";");
for(unsigned int i = 0; i < tokens.size(); i++)
{
string trimmed = trim(tokens[i], " ");
cout << i << ". Wort = " << (trimmed.empty() ? "leer" : "nicht leer") << endl;
}
[hüstel]
void Tokenize(const string& str,
vector<string>& tokens,
const string& delimiters = " ")
{
// Skip delimiters at beginning.
string::size_type lastPos = str.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
string::size_type pos = str.find_first_of(delimiters, lastPos);
while (string::npos != pos || string::npos != lastPos)
{
// Found a token, add it to the vector.
tokens.push_back(str.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = str.find_first_of(delimiters, lastPos);
}
}
std::string trim ( std::string const& str, char const* sepSet="")
{
std::string::size_type const first = str.find_first_not_of(sepSet);
return ( first==std::string::npos )
? std::string()
: str.substr(first, str.find_last_not_of(sepSet)-first+1);
}
[/hüstel]