//字符串分割函数 AKAI
std::vector<std::string> CDoorAccessFd::split(std::string str,std::string pattern)
{
std::string::size_type pos;
std::vector<std::string> result;
str+=pattern;//扩展字符串以方便操作
int size=str.size();
for(int i=0; i<size; i++)
{
pos=str.find(pattern,i);
if(pos<size)
{
std::string s=str.substr(i,pos-i);
result.push_back(s);
i=pos+pattern.size()-1;
}
}
return result;
} 记得包含相关头文件.
C++ string 跨平台 字符串分割函数
最新推荐文章于 2022-06-28 18:05:32 发布
本文介绍了一种使用C++实现的字符串分割函数,该函数能够将输入的字符串按照指定的模式进行切割,并返回一个保存所有子串的vector容器。通过扩展原始字符串并遍历查找模式来完成分割操作。
408

被折叠的 条评论
为什么被折叠?



