C++ trim function
Submitted by dv on Tue, 2008-04-15 17:25.
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
Archives
| August 2008 | ||||||
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 | ||||||
Recent comments
- Whoops
17 weeks 2 days ago - You can script the
17 weeks 2 days ago - Yep, I’m aware of that
28 weeks 5 days ago - I assume you’re aware of
28 weeks 6 days ago - loob
34 weeks 1 day ago










Post new comment