存档八月 1, 2006

C++ STL实现的string trim函数

代码真的很简洁啊。

std::string trim(std::string& s, const std::string& drop = ” “)
{
// trim right
std::string r=s.erase(s.find_last_not_of(drop)+1);
// trim left
return r.erase(0,r.find_first_not_of(drop));
}

评论(1)