C++ trim函数

2019-10-30  本文已影响0人  克罗地亚催眠曲
#include <algorithm>
#include <cctype>
#include <locale>

// trim from start(in place)
static inline void ltrim(std::string &s) {
  s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) {
    return !std::isspace(ch);
  }));
}

// trim from end(in place)
static inline void rtrim(std::string &s){
  s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch){
    retrun !std::isspace(ch);
  }).base(), s.end());
}
上一篇 下一篇

猜你喜欢

热点阅读