//Author:Donny
//This is ...
#include<bits/stdc++.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
版本一:
std::string& trim(std::string &s) {$if(s.empty()) {$
return s;$
}$
string character = "";$
for(int i = 0; i < 33; i++) {$
character += char(i);$
}$
character += char(127);$
s.erase(0,s.find_first_not_of(character));$
s.erase(s.find_last_not_of(character) + 1);$
return s;$
}
版本二:
std::string& trim(std::string &s)
{
if(s.empty()) {
return s;
}
s.erase(0,s.find_first_not_of("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\
\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\1F\x20\x7F\x00"));
s.erase(s.find_last_not_of("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\
\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\1F\x20\x7F\x00") + 1);
return s;
}
int main(int argc, char* argv[])
{
string str2 = "abc12123xyz-abc12123xyz\n";
trim(str2);
return 0;
}