zoukankan      html  css  js  c++  java
  • 一个类似Java String[] split(String regex)的VC++函数

    http://hi.baidu.com/ccskun/blog/item/9c4d033219ab5bfe1b4cff41.html/cmtid/1ce9b84445d57e2dcffca3d3

    INT_PTR Split_CString(const CString& source,//需要截取的原字符串
                      CStringArray& dest,//分割后的字符串数组
                      const CString& division//用做分割符的字符串
                      )//使用方式:Split(strViewString, dest, "<div id="pro_detail">");
    {
        if( source.IsEmpty() )
            return -1;
        dest.RemoveAll();
        int len = division.GetLength();
        int iFirst = 0;
        int nCount = 0;
        int pos = 0;
        int pre_pos = -1;
        while( -1 != pos )
        {
            if( -1 == pre_pos )
                pos = source.Find(division,pos);
            else
                pos = source.Find(division,(pos+1));

            if( -1 == pre_pos )
            {
                iFirst = 0;
                if( -1 == pos )
                    nCount = source.GetLength();
                else
                    nCount = pos;
            }
            else
            {
                iFirst = pre_pos+len;
                if( -1 != pos )
                    nCount = pos - pre_pos - len;
                else
                    nCount = source.GetLength()-pre_pos-len;
            }

            dest.Add(source.Mid(iFirst,nCount));

            pre_pos = pos;
        }

        return dest.GetCount();

    我也写了一个,

    Int PA_CStringSplit(CString strSource, CString strSplitter, CStringArray &saDestination) {
        INT m_iLen_source = strSource.GetLength();
        INT m_iLen_splitter = strSplitter.GetLength();
        INT iStart = 0;
        INT iLen = 0;
        INT iPos = 0;
     saDestination.RemoveAll();
        do {
            iPos = strSource.Find(strSplitter, iStart);
            if ( -1== iPos) {
                iLen = m_iLen_source - iStart;
            } else {
                iLen = iPos - iStart;
            }
            saDestination.Add(strSource.Mid(iStart, iLen));
            iStart += iLen + m_iLen_splitter;
        } while (iStart < m_iLen_source);
        return TRUE;
    }

  • 相关阅读:
    jQuery插件主要有两种扩展方式
    系统负载测试工具-LoadRunner
    安全扫描工具-AppScan
    newinstance()和new有什么区别?(转)
    类的加载、连接和初始化 (转)
    tar 基础
    了解【重放攻击】
    DDLDMLDCLDQL
    web.xml的配置问题
    组合与聚合
  • 原文地址:https://www.cnblogs.com/cy163/p/1757715.html
Copyright © 2011-2022 走看看