记录学习过程中的点点滴滴
为STL中的std::string添加trim函数的实现
代码如下:
//自定义trim函数
string trim(string& str)
{
string::size_type pos = str.find_last_not_of(‘ ‘);
if(pos != string::npos)
{
str.erase(pos + 1);
pos = str.find_first_not_of(‘ ‘);
if(pos != string::npos) str.erase(0, pos);
}
else str.erase(str.begin(), str.end());
return str;
本文地址:http://www.yaronspace.cn/blog/index.php/archives/149
来自yaronspace.cn 本文链接:http://yaronspace.cn/blog/archives/149您可能对下面文章也感兴趣:
这篇文章由admin于2009 年 11 月 14 日 22:31发表在编程语言与算法设计。你可以订阅RSS 2.0 也可以发表评论或引用到你的网站。 |