Created
January 4, 2010 06:38
-
-
Save saga/268360 to your computer and use it in GitHub Desktop.
std::string split function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void split(const string& str, const string& delim, vector<string>* pParts) | |
{ | |
size_t start, end = 0; | |
while (end < str.size()) { | |
start = end; | |
while (start < str.size() && (delim.find(str[start]) != string::npos)) | |
{ | |
start++; // skip initial whitespace | |
} | |
end = start; | |
while (end < str.size() && (delim.find(str[end]) == string::npos)) | |
{ | |
end++; // skip to end of word | |
} | |
if (end - start != 0) { // just ignore zero-length strings. | |
pParts->push_back(string(str, start, end-start)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment