C++ 使用STL string 实现的split,trim,replace
实现string 的去除两边空格,按指定字符截取,替换 #include <iostream> #include <vector> using namespace std; namespace strtool { string trim(const string& str) { string : :size_type pos = str.find_first_not_of(' ') ; if (pos == string : :npos) { return str ; } string::size_type pos2 = str.find_last_not_of(' '); if (pos2 != string::npos) { return str.substr(pos, pos2 - pos + 1); } return str.substr(pos); } int split(const string& str, vector<string>& ret_, string sep = ",") { if (str.empty()) { return 0; } string tmp; string::size_type pos_begin = str.find_first_not_of(sep); string::size_type comma_pos = 0; while