Created
June 25, 2018 07:16
-
-
Save jiemojiemo/f5dad264eda499b7723ebb28e881a4ce to your computer and use it in GitHub Desktop.
Cpp-split a string
This file contains hidden or 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 SplitString(const std::string& s, std::vector<std::string>& v, const std::string& c) | |
{ | |
std::string::size_type pos1, pos2; | |
pos2 = s.find(c); | |
pos1 = 0; | |
while(std::string::npos != pos2) | |
{ | |
v.push_back(s.substr(pos1, pos2-pos1)); | |
pos1 = pos2 + c.size(); | |
pos2 = s.find(c, pos1); | |
} | |
if(pos1 != s.length()) | |
v.push_back(s.substr(pos1)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment