//按英文逗号分隔字符串
std::vector<string> splitStringLi(string destStr)
{
vector<string> tempStrVec;
if (destStr == "")
{
tempStrVec.push_back("");
return tempStrVec;
}
if (destStr.find(',', 0) == string::npos)
{
tempStrVec.push_back(destStr);
return tempStrVec;
}
int index = 0;
for (int i = 0; i < destStr.length(); ++i)
{
if (destStr.at(i) == ',')
{
tempStrVec.push_back(destStr.substr(index, i - index));
index = i + 1;
}
if (index >= destStr.length())
{
break;
}
if ((destStr.substr(index)).find(",", 0) == string::npos)
{
tempStrVec.push_back(destStr.substr(index));
break;
}
}
return tempStrVec;
}
【C++常用API】按英文逗号分割字符串(‘,‘)
于 2024-05-11 12:11:12 首次发布