Last active
August 29, 2015 14:06
-
-
Save pdxjohnny/a18b8ec92b69bb8f11b0 to your computer and use it in GitHub Desktop.
Split On Substring
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
std::vector<std::string> split_line(std::string str, std::string sub) | |
{ | |
std::vector<std::string> vector_split_line; | |
std::string split_line = ""; | |
std::string sub_line = ""; | |
bool skip = false; | |
for ( int current_char = 0; current_char < str.length(); current_char++ ) | |
{ | |
if ( str[current_char] == sub[0] ) | |
{ | |
sub_line = ""; | |
for ( int i = 0; i < sub.length(); i++ ) | |
{ | |
sub_line += str[ current_char + i ]; | |
} | |
if (sub_line.compare(sub) == 0) | |
{ | |
current_char += sub.length(); | |
skip = true; | |
} | |
} | |
if ( skip ) | |
{ | |
skip = false; | |
vector_split_line.push_back(split_line); | |
split_line = ""; | |
current_char--; | |
} | |
else | |
{ | |
split_line += str[current_char]; | |
} | |
} | |
vector_split_line.push_back(split_line); | |
return vector_split_line; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment