C++ STL实现的string trim函数

Keep Open and Learning
Post Reply
星际浪子
Posts: 3597
Joined: 01 May 2009 23:45

C++ STL实现的string trim函数

Post by 星际浪子 » 10 Jul 2011 15:30

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

Post Reply