您的位置:首页 > 编程语言 > C语言/C++

(转帖)如何将字符串前后的空白去除? (使用string.find_first_not_of, string.find_last_not_of) (C/C++)

2009-03-31 23:40 741 查看
转帖博客地址
http://www.cnblogs.com/oomusou/archive/2006/11/17/564197.html
下面的函数定义可以将string的前后空白去掉,在处理读入的字符串时非常有用。

std::string& trim(std::string &s)
{
if (s.empty())
{
return s;
}
s.erase(0,s.find_first_not_of(" "));
s.erase(s.find_last_not_of(" ") + 1);
return s;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐