Created
March 15, 2016 12:14
-
-
Save blippy/dc2d8c0a09a5ef7b0a61 to your computer and use it in GitHub Desktop.
trim a string of a set of characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const char white[] = " \t\r"; | |
| string trim(string& str) | |
| { | |
| if(str.length() ==0) { return str;} | |
| size_t first = str.find_first_not_of(white); | |
| if(first == string::npos) return ""; | |
| size_t last = str.find_last_not_of(white); | |
| return str.substr(first, (last-first+1)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that it trims the left and right extremities of a string, not the whole string itself.