Here's how I did it in straight C++ with STL before. Can I do something similar in Qt?
void ParseSentence( string& mSentence,
string& mDelimiters,
vector<string>& mFields )
{
// Skip delimiters at beginning.
string::size_type lastPos = mSentence.find_first_not_of( mDelimiters, 0);
// Find first "non-delimiter".
string::size_type pos = mSentence.find_first_of( mDelimiters, lastPos);
while (string::npos != pos || string::npos != lastPos)
{
// Found a token, add it to the vector.
mFields.push_back( mSentence.substr( lastPos, pos - lastPos ) );
// Skip delimiters. Note the "not_of"
lastPos = mSentence.find_first_not_of( mDelimiters, pos );
// Find next "non-delimiter"
pos = mSentence.find_first_of( mDelimiters, lastPos );
}
}
void ParseSentence( string& mSentence,
string& mDelimiters,
vector<string>& mFields )
{
// Skip delimiters at beginning.
string::size_type lastPos = mSentence.find_first_not_of( mDelimiters, 0);
// Find first "non-delimiter".
string::size_type pos = mSentence.find_first_of( mDelimiters, lastPos);
while (string::npos != pos || string::npos != lastPos)
{
// Found a token, add it to the vector.
mFields.push_back( mSentence.substr( lastPos, pos - lastPos ) );
// Skip delimiters. Note the "not_of"
lastPos = mSentence.find_first_not_of( mDelimiters, pos );
// Find next "non-delimiter"
pos = mSentence.find_first_of( mDelimiters, lastPos );
}
}
To copy to clipboard, switch view to plain text mode
example of usage:
// Parse sentence
ParseSentence( str,
string(", *"),
str_fields );
example of usage:
// Parse sentence
ParseSentence( str,
string(", *"),
str_fields );
To copy to clipboard, switch view to plain text mode
Bookmarks