zoukankan      html  css  js  c++  java
  • string分割


    #include <string>
    #include <vector>
    using std::string;  //使用string对象
    using std::vector;  //使用vector
     
     
     
    void Split(const std::string& src, const std::string& separator, std::vector<std::string>& dest);//函数原型
     
     
    void Split(const std::string& src, const std::string& separator, std::vector<std::string>& dest) //字符串分割到数组
    {
     
            //参数1:要分割的字符串;参数2:作为分隔符的字符;参数3:存放分割后的字符串的vector向量
     
     string str = src;
     string substring;
     string::size_type start = 0, index;
     dest.clear();
     index = str.find_first_of(separator,start);
     do
     {
      if (index != string::npos)
      {   
       substring = str.substr(start,index-start );
       dest.push_back(substring);
       start =index+separator.size();
       index = str.find(separator,start);
       if (start == string::npos) break;
      }
     }while(index != string::npos);
     
     //the last part
     substring = str.substr(start);
     dest.push_back(substring);
    }
  • 相关阅读:
    Mkdocs文档生成
    IntelliJ IDEA
    WPS中页眉设置
    ubuntu下的画图工具-dia
    接口测试详细过程
    ubuntu下安装jmeter
    互联网产品接入支付功能如何测试?
    Uiautomator自动化测试编写和调试
    Ubuntu下配置android环境
    UIAutomator环境配置与运行
  • 原文地址:https://www.cnblogs.com/toujizhe/p/12079061.html
Copyright © 2011-2022 走看看