出处:http://www.cnblogs.com/lzjsky/archive/2011/01/23/1942508.html

1. 查找字符

 std::wstring  strData = L"<result>[北京市, 上海市, 深圳市]</result>"

 void DoF(const std::wstring &strData, std::list<std::wstring>& listDo)

 {

     std::wstring strTarB = L"<result>[";

     std::wstring strTarE = L"]</result>";

     std::wstring::size_type nBeginTempB = , nEndTempB = , nBeginTempE = , nEndTempE = ;

     nEndTempB = strData.find(strTarB, nBeginTempB);

     nEndTempE = strData.find(strTarE, nBeginTempE);

     if(nEndTempB != std::wstring::npos && nEndTempE != std::wstring::npos && nEndTempE > nEndTempB + strTarB.length())

     {

         std::wstring strTemp = strData.substr(nEndTempB + strTarB.length(), nEndTempE -  nEndTempB - strTarB.length());

         std::wstring strSub;

         strTemp += L",";

         std::list<std::wstring>::iterator it;

         listDo.clear();

         std::wstring::size_type nBegin = , nEnd = ;

         while( (nEnd = strTemp.find(L",", nBegin)) != std::wstring::npos)

         {

             strSub = strTemp.substr(nBegin, nEnd - nBegin);

             if(strSub.length() > )

             {

                 listDo.push_back(strSub);

             }

             nBegin = nEnd + ;

         }

     }

 }

2. 替换字符串

stl 中的string只是提供了按照位置和区间的replace函数,而不能用一个string字串来替换指定string中的另一个字串.

 void string_replace(std::string& strBig, const std::string & strsrc, const std::string &strdst)

 {

      std::string::size_type pos = ;

      while( (pos = strBig.find(strsrc, pos)) != string::npos)

      {

          strBig.replace(pos, strsrc.length(), strdst);

          pos += strdst.length();

      }

 }

 // 使用

 std::string strinfo= "This is Winter, Winter is a programmer. Do you know Winter?";

 // 把strinfo中的所有"Winter" 替换为"wende"

 string_replace(strinfo, "Winter", "wende");

stl string 使用(转载)的更多相关文章

  1. 格式字符串分配stl::string

    代码非常easy,不解释,直接在代码: #include <cstdio> #include <cstdarg> #include <iostream> using ...

  2. 深入剖析 linux GCC 4.4 的 STL string

    转自: 深入剖析 linux GCC 4.4 的 STL string 本文通过研究STL源码来剖析C++中标准模板块库std::string运行机理,重点研究了其中的引用计数和Copy-On-Wri ...

  3. 浅谈C++ STL string容器

    浅谈C++ STL string容器 本篇随笔简单讲解一下\(C++STL\)中\(string\)容器的使用方法及技巧. string容器的概念 其实\(string\)并不是\(STL\)的一种容 ...

  4. C++标准模板库Stand Template Library(STL)简介与STL string类

    参考<21天学通C++>第15和16章节,在对宏和模板学习之后,开启对C++实现的标准模板类STL进行简介,同时介绍简单的string类.虽然前面对于vector.deque.list等进 ...

  5. 转C++之stl::string写时拷贝导致的问题

    前几天在开发某些数据结构到文件的 Dump 和 Load 功能的时候, 遇到的一个 bug . [问题复现] 问题主要出在 Load 过程中,从文件读取数据的时候, 直接使用 fread 的去操作 s ...

  6. [转载] C++ STL string的Copy-On-Write技术

    原文: http://coolshell.cn/articles/12199.html stl的string是经过严格优化的, 深入理解对以后编程过程中应用string非常有益处, 感谢左耳朵耗子的精 ...

  7. 【转载】 C++ stl string 操作

        总结一下C++中string的操作,来自〈C++ Primer〉第四版. 1. string对象的定义和初始化: 12345678910111213 string s1; //空串string ...

  8. STL——string

    C++之string类型详解 之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必担心内存是否足够.字符串长度等等,而且作为一个泛型类出现,他集成的操作函 ...

  9. stl, string不仅是charString, 更是byteString

     转载至:http://chzhou.blog.sohu.com/97459512.html 以前一直没有注意到STL中的string的length函数,但一直用它.天真的以为它会返回字符串的长度 ...

随机推荐

  1. 不移除通知的话,出现的bug

    没销毁的私聊控制器仍然监听到了通知,发送表情

  2. Set-cookie无效(失效)

    今天做爬虫的时候遇到网站响应response返回的数据中有Set-Cookie,但是使用Linux的curl请求网页保存cookie始终为空,换句话说也就是Set-Cookie设置无效,所以我一直Go ...

  3. Mybatis 代码自动生成[myeclipse版]

    使用环境说明: OS:windows 7 64位 myeclipse: 2017 CI 1.安装 打开myeclipse--help---Install from catalog--选择eclipse ...

  4. 常用的windows注册表大全

    目录 使系统没有“运行”选项                        1让操作系统无“关闭系统” 选项                    2让操作系统无“注销”选项              ...

  5. nodejs(三)Buffer module & Byte Order

    一.目录 ➤ Understanding why you need buffers in Node ➤ Creating a buffer from a string ➤ Converting a b ...

  6. curl 一个无比有用的网站开发工具

    1.Common Line Url Viewer curl是一种命令行工具,作用是发出网络请求,然后得到和提取数据,显示在"标准输出"(stdout)上面. 2.-i参数可以显示h ...

  7. 01_Python 基础课程安排

    Python 基础课程安排 目标 明确基础班课程内容 课程清单 序号 内容 目标 01 Linux 基础 让大家对 Ubuntu 的使用从很 陌生 达到 灵活操作 02 Python 基础 涵盖 Py ...

  8. iOS中textbox文本框清除圆角

    在iOS.Mac safari中,所有的textbox, select, checkbox都会被强制美化为圆角.但在特殊情况下需要清除圆角时发现iOS中使用以下传统的css无效: border-rad ...

  9. nginx 11个处理阶段 && nginx lua 8个处理阶段

    1. nginx 11 个处理阶段 nginx实际把请求处理流程划分为了11个阶段,这样划分的原因是将请求的执行逻辑细分,各阶段按照处理时机定义了清晰的执行语义,开发者可以很容易分辨自己需要开发的模块 ...

  10. Ng线性回归实现学习[转载]

    转自:https://github.com/huanting74/Coursera-ML-AndrewNg 1.可视化数据 import pandas as pd import seaborn as ...