Skip to content

Instantly share code, notes, and snippets.

@pdxjohnny
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdxjohnny/a18b8ec92b69bb8f11b0 to your computer and use it in GitHub Desktop.
Save pdxjohnny/a18b8ec92b69bb8f11b0 to your computer and use it in GitHub Desktop.
Split On Substring
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