Skip to content

Instantly share code, notes, and snippets.

@cybersmyth
cybersmyth / chomp.cpp
Last active January 19, 2023 22:36 — forked from rocarvaj/chomp.cpp
C++ string chomp
void chomp (string& str,string victims="\n \t\r")
{
string::size_type pos = str.find_last_not_of(victims);
if(pos != string::npos)
str = str.substr(0, pos+1);
else
str = "";
}
/*
* Weed just removes all characters in the "weeds" string from the source string
*/
string weed (string& str,string weeds="\n \t\r")
{
string rv;
for (char c : str)
if ((weeds.find(c) == string::npos))
rv.insert(rv.end(),c);
return rv;