Add split string function #4933

This commit is contained in:
Jerry (Xinyu Hou)
2015-10-29 12:52:55 -07:00
parent 27f83e1801
commit 72397137c0
2 changed files with 27 additions and 0 deletions

View File

@@ -224,6 +224,26 @@ stringToSizeType(String string)
return value;
}
std::vector<String>
splitString(String string, const char c)
{
std::vector<String> results;
size_t head = 0;
size_t separator = string.find(c);
while (separator != String::npos) {
results.push_back(string.substr(head, separator - head));
head = separator + 1;
separator = string.find(c, head);
}
if (head < string.size()) {
results.push_back(string.substr(head, string.size() - head));
}
return results;
}
//
// CaselessCmp
//