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;
}

版权声明:本文博主原创文章。博客,未经同意不得转载。

高效实现 std::string split() API的更多相关文章

  1. std::string的split函数

    刚刚要找个按空格分离std::string的函数, 结果发现了stackoverflow上的这个问题. 也没仔细看, 直接拿来一试, 靠, 不对啊, 怎么分离后多出个空字符串, 也就是 "a ...

  2. 如何使用 window api 转换字符集?(std::string与std::wstring的相互转换)

    //宽字符转多字节 std::string W2A(const std::wstring& utf8) { int buffSize = WideCharToMultiByte(CP_ACP, ...

  3. C++: std::string 与 Unicode 结合

    一旦知道 TCHAR 和_T 是如何工作的,那么这个问题很简单.基本思想是 TCHAR 要么是char,要么是 wchar_t,这取决于_UNICODE 的值: // abridged from tc ...

  4. C++: std::string 与 Unicode 如何结合?

    关键字:std::string Unicode 转自:http://www.vckbase.com/document/viewdoc/?id=1293 一旦知道 TCHAR 和_T 是如何工作的,那么 ...

  5. std::string 用法总结

    标准C++中的string类的用法总结 相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用.但是如果离开了MFC框架,还有 ...

  6. 【转】java String.split()函数的用法分析

      在java.lang包中有String.split()方法的原型是: public String[] split(String regex, int limit) split函数是用于使用特定的切 ...

  7. Java: String.split(....); 结果很意外

    String txt = "join|公共聊天室||"; String[] paras = txt.splite("\\|"); String t1 = par ...

  8. std::string 字符串切割

    在很多字符串类库里都实现了split函数.不过在std里没有实现.在这里拿出几个: 1. 用单字符作为分隔 #include <string> #include <vector> ...

  9. std::u32string conversion to/from std::string and std::u16string

    I need to convert between UTF-8, UTF-16 and UTF-32 for different API's/modules and since I know have ...

随机推荐

  1. directsound 应用实例

    sdk里边有个文件夹Samples\C++\XInput\AudioController这个就是

  2. discuz二次开发技巧

    discuz二次开发技巧 二次开发大多时候知识设置和处理,如果能够获知模板文件获得的变量数组将大大提高我们的开发效率 获取页面已经定义的变量 <--{eval printf_r(get_defi ...

  3. Flask jQuery ajax

    http://www.runoob.com/jquery/jquery-ref-ajax.html http://jun1986.iteye.com/blog/1399242 下面是jQuery官方给 ...

  4. 手工构建ISO的基本步骤

    1.完成rpm包的构建 登录测试机,ssh 10.xx.xx.xxx cd /home/svn/desktop/trunk/ svn update                            ...

  5. Python新手学习基础之初识python——与众不同2

    看完了Python的缩进,现在来看看Python的标识符.引号和注释. 标识符 关于Python的标识符,其实不是与众不同,只是有一定的规则. 标识符是编程时使用的名字.在Python中,标识符有几点 ...

  6. Python Tutorial 学习(九)--Classes

    ## 9. Classes 类 Compared with other programming languages, Python's class mechanism adds classes wit ...

  7. linux配置记录

    今天想把开发环境都配置到linux环境来,所以用wubi挂载了个ubuntu系统(64位),因为不常使用linux所以把今天学到的一些 东西记下来以做备查. #1.   java环境配置 到oracl ...

  8. Catharanthus roseus(长春花碱)的生物合成

    标题:Directed Biosynthesis of Alkaloid Analogs in the Medicinal Plant Catharanthus roseus 作者:Elizabeth ...

  9. 一个C#的XML数据库访问类

    原文地址:http://hankjin.blog.163.com/blog/static/33731937200942915452244/ 程序中不可避免的要用到配置文件或数据,对于数据量比较小的程序 ...

  10. jQuery--Promise object

    http://blog.mediumequalsmessage.com/promise-deferred-objects-in-javascript-pt2-practical-use http:// ...