1) QString split(QRegexp("\\s+"))
比c++效率低
2)C++
#include <iostream>
#include <vector>
void devideStringByChar(const std::string& strToDevide, std::vector<std::string> &strDevidedVec, char ch = ' ')
{
std::string str = strToDevide;
strDevidedVec.clear();
int num = 0;
int startPos, endPos, nPos = 0;
int strLen = str.length();
while (true)
{
startPos = str.find_first_not_of(ch, nPos);
if (startPos < 0)
break;
endPos = str.find_first_of(ch, startPos);
if (endPos < 0)
{
strDevidedVec.push_back(str.substr(startPos, strLen - endPos));
break;
}
std::string temp = str.substr(startPos, endPos - startPos);
strDevidedVec.push_back(temp);
nPos = endPos;
}
}
int main()
{
std::vector<std::string> strVec;
std::string str = "ab cd ef \r";
devideStringByChar(str, strVec);
return 0;
}