Created
August 21, 2017 23:40
-
-
Save rebelmachina/24755679039acdf4d7cd96997966e1b2 to your computer and use it in GitHub Desktop.
strip surrounding spaces in C++
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
| string stripSurroundingSpaces(string s) { | |
| int i = 0; | |
| while(i<s.size() && s[i] == ' ') { | |
| i++; | |
| } | |
| int j = s.size()-1; | |
| while(j >= 0 && s[j] == ' ') { | |
| j--; | |
| } | |
| string res; | |
| for(int k=i; k<=j; ++k) | |
| res += s[k]; | |
| return res; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment