C++ 删除字符串前后空白函数

来源:互联网 发布:linux文件夹权限设置 编辑:程序博客网 时间:2024/06/03 03:04

本函数来自于 Ice 项目,以前不知道标准库中有find_first_not_of,find_last_not_of函数。

#include <string>

using namespace std;

string trim(const string& s)

{
    static const string delims = "/t/r/n ";
    string::size_type last = s.find_last_not_of(delims);
    if(last != string::npos)
    {
        return s.substr(s.find_first_not_of(delims), last+1);
    }
    return s;
}

 

原创粉丝点击