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

    头文件:

     Cstring trim(char ch = ' ');
     std::vector<Cstring> split(const Cstring & strSep,bool needTrim = true);

    cpp 文件:

    Cstring Cstring::trim(char ch)
    {
        TrimLeft(ch);
        TrimRight(ch);
        return *this;
    }

    std::vector<Cstring> Cstring::split(const Cstring & strSep,bool needTrim)
    {
        std::vector<Cstring> strsRet;

        if (needTrim == true)
        {
           trim();
        }
        for(;;)
        {
            Cstring temp;
            int pos = (int)find(strSep);
            if(pos == (int)bam_string::npos)
            {
                temp = needTrim?this->trim():*this;

                if(!temp.empty())
                {
                    strsRet.push_back(temp);
                }
                break;
            }
            else
            {
                temp = substr(0,pos);
                if(needTrim == true)
                {
                    temp = temp.trim();
                }
                if(!temp.empty())
                {
                    strsRet.push_back(temp);
                }

                *this = this->substr(strSep.size()+pos,this->size() - strSep.size()+pos);

            }
        }

        return strsRet;
    }

    trim 的实现的备注:

    void Cstring::TrimLeft(const char* trim )
    {
        erase(0,find_first_not_of(trim));
    }

  • 相关阅读:
    并发与多线程
    java多线程--死锁
    java变量
    StringStringBufferStringBuilder区别
    java8新特性
    spring自动装配和通过java实现装配
    CSP -- 运营商内容劫持(广告)的终结者
    【Composer】实战操作二:自己创建composer包并提交
    【个人重点】开发中应该重视的几点
    【Composer】实战操作一:使用库
  • 原文地址:https://www.cnblogs.com/haibianxiaolu/p/3881086.html
Copyright © 2011-2022 走看看