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.

Trackback URL for this post:

http://glyphy.com/trackback/33

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Comments feed Comments feed