1 std::vector<std::string> split(const std::string &input) { 2 const std::string alpha {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"}; 3 std::vector<std::string> result; 4 size_t begin = 0; 5 while (begin < input.size()) { 6 if ((begin = input.find_first_of(alpha, begin)) == std::string::npos) { 7 break; 8 } 9 size_t end; 10 if ((end = input.find_first_not_of(alpha, begin)) == std::string::npos) { 11 result.push_back(input.substr(begin)); 12 break; 13 } 14 result.push_back(input.substr(begin, end - begin)); 15 begin = end + 1; 16 } 17 return result; 18 }
原文:https://www.cnblogs.com/ren-yu/p/12026756.html