Skip to content

Instantly share code, notes, and snippets.

@tkymx
Last active April 15, 2016 07:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkymx/6e910363cb04aa3eef3e0e0d644ea062 to your computer and use it in GitHub Desktop.
Save tkymx/6e910363cb04aa3eef3e0e0d644ea062 to your computer and use it in GitHub Desktop.
std::vector<std::string> split(std::string text,std::string delim )
{
int index = 0, current = 0;
std::vector<std::string> strs;
while ((index = text.find_first_of(delim, current)) != std::string::npos)
{
strs.push_back(text.substr(current, index - current));
current = index + 1;
}
strs.push_back(text.substr(current,text.size()-current));
return strs;
}
std::string trim(std::string text )
{
int r = text.find_first_not_of(" \t");
int l = text.find_last_not_of(" \t");
if (r == std::string::npos || l == std::string::npos)
return text;
return text.substr(r,l-r+1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment