本函数来自于 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;
}
本文介绍了一个实用的字符串处理函数,该函数使用C++标准库中的find_first_not_of和find_last_not_of函数来去除字符串首尾的空白字符。通过具体代码实现展示了如何高效地清理字符串。
3214

被折叠的 条评论
为什么被折叠?



