高效实现 std::string split() API
Qt下一个 QString 实现split()性能。和std::string未实现它的。STL也未实现。只有自己可以写一。
#include <string>
#include <vector>
using namespace std;
vector<string> split(string strtem,char a)
{
vector<string> strvec;
string::size_type pos1, pos2;
pos2 = strtem.find(a);
pos1 = 0;
while (string::npos != pos2)
{
strvec.push_back(strtem.substr(pos1, pos2 - pos1));
pos1 = pos2 + 1;
pos2 = strtem.find(a, pos1);
}
strvec.push_back(strtem.substr(pos1));
return strvec;
}
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/66502.html
- 上一篇:delphi监控文件夹
- 下一篇:Linq To XML创建XML