c++

C++ trim function

in

Trim function for C++ std::string:

using namespace std;
#include <string>
 
inline string trim(const string& o) {
  string ret = o;
  const char* chars = "\n\t\v\f\r ";
  ret.erase(ret.find_last_not_of(chars)+1);
  ret.erase(0, ret.find_first_not_of(chars));
  return ret;
}

It returns a new string, sort of like it’s done in Qt or Java.

Posts feed Posts feed