Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- using namespace std;
- const std::string WHITESPACE = " \n\r\t\f\v";
- std::string ltrim(const std::string& s)
- {
- size_t start = s.find_first_not_of(WHITESPACE);
- return (start == std::string::npos) ? "" : s.substr(start);
- }
- std::string rtrim(const std::string& s)
- {
- size_t e = s.find_last_not_of(WHITESPACE);
- return (e == std::string::npos) ? "" : s.substr(0, e + 1);
- }
- std::string trim(const std::string& s)
- {
- return rtrim(ltrim(s));
- }
- int main()
- {
- std::string s[10];
- s[1] = "\n\t g hwetHello World \r\n ";
- std::cout << "START::" << trim(s[1]) << "::end\n";
- s[2]=" jkhgdlkj ";
- cout<<trim(s[2]);
- return 0;
- }
Add Comment
Please, Sign In to add comment