C++标准库写的split函数,支持字符串作为切割符号
作者:互联网
void split(const std::string& inputStr, const std::string& seperateStr, std::vectorstd::string& ouputVec)
{
std::string::size_type startPos = 0;
std::string::size_type sepPos = inputStr.find(seperateStr, startPos);
while (sepPos != std::string::npos) {
std::string singleStr = inputStr.substr(startPos, sepPos - startPos);
if (singleStr.size() > 0) {
ouputVec.push_back(singleStr);
}
startPos = sepPos + seperateStr.size();
sepPos = inputStr.find(seperateStr, startPos);
}
if (startPos + seperateStr.size() < inputStr.size() - 1) {
std::string singleStr = inputStr.substr(startPos, inputStr.size() - 1);
ouputVec.push_back(singleStr);
}
}
weixin_42491321 发布了1 篇原创文章 · 获赞 0 · 访问量 12 私信 关注标签:std,库写,sepPos,string,C++,split,inputStr,startPos,size 来源: https://blog.csdn.net/weixin_42491321/article/details/104464715