字符串分割

 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 }
posted @ 2019-12-12 01:01  Ren.Yu  阅读(129)  评论(0编辑  收藏  举报