zoukankan      html  css  js  c++  java
  • c++ 字符串分割

    void split(const string& str, vector<string>& ret_, string sep)--传入要分割的字符串str,要存储分割字符串的ret,分割的字符串str

    {

        if (str.empty())

        {

            return;

        }

        

        string tmp;

        string::size_type pos_begin = str.find_first_not_of(sep);

        string::size_type comma_pos = 0;

        

        while (pos_begin != string::npos)

        {

            comma_pos = str.find(sep, pos_begin);

            if (comma_pos != string::npos)

            {

                tmp = str.substr(pos_begin, comma_pos - pos_begin);

                pos_begin = comma_pos + sep.length();

            }

            else

            {

                tmp = str.substr(pos_begin);

                pos_begin = comma_pos;

            }

            

            if (!tmp.empty())

            {

                ret_.push_back(tmp);

                tmp.clear();

            }

        }

    }

  • 相关阅读:
    websocket
    svg vs canvas
    nw
    web sql
    web worker
    【转载】磁盘阵列详解
    【识记】开源软件系列
    【转载】从1.5K到18K 一个程序员的5年成长之路
    SQL中in和not in
    SQL Server select count(distinct *)
  • 原文地址:https://www.cnblogs.com/HemJohn/p/5205624.html
Copyright © 2011-2022 走看看