It depends, but I use 3 methods
#include <algorithm>
#include <functional>
#include <cctype>
#include <locale>
//Remove opening characters in front of you
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;
}
//Remove open characters after
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;
}
//Remove open characters at both ends
static inline std::string &trim(std::string &s) {
return ltrim(rtrim(s));
}
© 2024 OneMinuteCode. All rights reserved.