Skip to content

Instantly share code, notes, and snippets.

@DJmong
Last active March 18, 2022 03:16
Show Gist options
  • Select an option

  • Save DJmong/591a676df7357a83b763830067d17ca7 to your computer and use it in GitHub Desktop.

Select an option

Save DJmong/591a676df7357a83b763830067d17ca7 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
std::vector<std::string> parseLine(std::string input, std::string del)
{
std::vector<std::string> result;
std::string parse = "";
for(size_t idx = 0; idx < input.size(); ++idx)
{
if(find(del.begin(), del.end(), input[idx]) == del.end())
{
parse += input[idx];
}
else if(!parse.empty())
{
result.push_back(parse);
parse = "";
}
if(idx+1 == input.size() && !parse.empty())
{
result.push_back(parse);
}
}
return result;
}
int main()
{
std::string input = "this,is!parse$test";
std::vector<std::string> result = parseLine(input, ",!$");
for(size_t idx = 0; idx < result.size(); ++idx)
{
std::cout << result[idx] << std::endl;
}
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment