zoukankan      html  css  js  c++  java
  • C++之以分隔符的形式获取字符串

    void CConvert::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);

    }

    vector<string> ster;
    vector<string>::iterator iter; //声明一个迭代器

    string str="ABC|123|AC123";
    string Insta;
    CString pourin;
    CConvert::Split(str, "|", ster);
    int lenth = 0;

    char charstr[200]={0};
    for (iter = ster.begin(); iter != ster.end(); iter++)
    {

    Insta = *iter;
    pourin = Insta.c_str();
    string Str = CT2A(pourin.GetBuffer());
    strcpy(charstr, Str.c_str());
    lenth++;
    }

  • 相关阅读:
    Matlab 画图
    OfferCome-0531
    OfferCome--0528
    剑指offer(2)
    剑指offer(1)
    MySQL的自增主键
    java Junit 测试
    sql 注入问题
    Facebook Libra
    markdown的博客
  • 原文地址:https://www.cnblogs.com/Pond-ZZC/p/11477169.html
Copyright © 2011-2022 走看看