(转帖)如何将字符串前后的空白去除? (使用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的前后空白去掉,在处理读入的字符串时非常有用。
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; }
相关文章推荐
- (原創) 如何将字符串前后的空白去除? (使用string.find_first_not_of, string.find_last_not_of) (C/C++)
- 如何将字符串前后的空白去除? (使用string.find_first_not_of, string.find_last_not_of) (C/C++)
- 字符串处理函数find_first_of和find_last_of的使用
- C++ 标准模板库学习之 string 类 详解 (一) 将一个句子中每个单词的单词字母顺序翻转 关于npos find_first_not_of find_first_of getline
- (原創) 如何使用find_first_of() algorithm? (C/C++) (STL)
- string中的find(),find_first_of(),find_first_not_of()之间区别
- C++基础---string类的find/find_first_of/find_first_not_of/rfind/find_last_of/find_last_not_of
- 20170604_string中的函数find_first_of()和 find_last_of()
- (原創) 如何将字符串前后的空白去除? (C/C++) (STL)
- string 中的 find()、 find_first_of()、find_first_not_of()
- string c++详解 find_first_not_of() find_first_of()
- 如何将字符串前后的空白去除(C/C++) (STL)
- string 类成员函数 find() / find_first_of() / find_last_of() 的用法详解
- std::string::find_last_not_of
- std::string 类中find_first_not_of ()函数
- string 中find_last_of的索引是字符串最后的字符,不是开始的字符的位置,记录一下
- 如何使用find_first_of() algorithm?
- std :: string :: find_first_not_of
- Spring Mvc使用Jackson进行json转对象时,遇到的字符串转日期的异常处理(Can not deserialize value of type Date from String)
- string::npos在 c++ 的find_first_of判断是什么意思