从以其他字符分隔的字符串中取数字段

vector<std::string> extractNums(const std::string& s) { vector<std::string> nums; bool extracting = false; auto begin = s.cbegin(); for (auto it = s.cbegin(); it != s.cend(); ++it){ if (extracting){ if (!std::isdigit(*it)){ nums.push_back (std::string(begin, it)); extracting = false; } }else{ if (std::isdigit(*it)){ begin = it; extracting = true; } } } if (extracting){ nums.push_back (std::string(begin, s.cend ())); } return nums; }

 

你可能感兴趣的:(从以其他字符分隔的字符串中取数字段)