Best Ways to Trim a string in C++ [stackoverflow]
Author
posted @ 2013年2月19日 05:48
in C/C++
, 3720 阅读
1. Using boost::algorithm
#include <boost/algorithm/string.hpp> using namespace std; using namespace boost::algorithm; string str1(" hello world! "); trim(str1);
2. Define inline function:
#include <algorithm> #include <functional> #include <cctype> #include <locale> // trim from start static inline std::string <rim(std::string &s) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace)))); return s; } // trim from end static inline std::string &rtrim(std::string &s) { s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end()); return s; } // trim from both ends static inline std::string &trim(std::string &s) { return ltrim(rtrim(s)); }
http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring
2022年1月19日 06:57
My experience with Caldwells was really not what I expected. They suggested things that I never knew I needed for my project. Check their site to https://caldwells.com/interior-doors/victorian-doors their products.
2022年2月10日 01:07
This type of message always inspiring and I prefer to read quality content, so happy to find good place to many here in the post, the writing is just great, thanks for the post. https://voyance-tel-avenir.com