日本好好热aⅴ|国产99视频精品免费观看|日本成人aV在线|久热香蕉国产在线

  • <cite id="ikgdy"><table id="ikgdy"></table></cite>
    1. 西西軟件園多重安全檢測(cè)下載網(wǎng)站、值得信賴的軟件下載站!
      軟件
      軟件
      文章
      搜索

      首頁編程開發(fā)VC|VC++ → c++實(shí)現(xiàn)字符串的替換replace函數(shù)

      c++實(shí)現(xiàn)字符串的替換replace函數(shù)

      相關(guān)軟件相關(guān)文章發(fā)表評(píng)論 來源:西西整理時(shí)間:2012/9/23 9:22:09字體大。A-A+

      作者:西西點(diǎn)擊:519次評(píng)論:0次標(biāo)簽: replace

      Actual Search and Replace(文件搜索)2.8.6 漢化綠色特別版
      • 類型:搜索比較大。398KB語言:中文 評(píng)分:5.0
      • 標(biāo)簽:
      立即下載

      用過python的朋友應(yīng)該知道,python的string中有個(gè)replace函數(shù),其功能是實(shí)現(xiàn)字符串的替換,默認(rèn)情況下是替換所有,如果加入?yún)?shù)的話會(huì)根據(jù)設(shè)定的個(gè)數(shù)進(jìn)行替換,比如下面的例子:

      >>> import string

      >>> str1 = "ab1ab2ab3ab4"

      >>> print string.replace(str1,"ab","cd")

      cd1cd2cd3cd4

      >>> print string.replace(str1,"ab","cd",1)

      cd1ab2ab3ab4

      >>> print string.replace(str1,"ab","cd",2)

      cd1cd2ab3ab4

      >>>

      在c++中,我也想這么用……暫時(shí)還沒找到現(xiàn)成的,就自己寫了個(gè)。

      這里貼出來函數(shù)的代碼,也方便我以后使用:

      std::string m_replace(std::string str,std::string pattern,std::string dstPattern,int count=-1)
      {
          std::string retStr="";
          string::size_type pos;

          int szStr=str.length();
          int szPattern=pattern.size();
          int i=0;
          int l_count=0;
          if(-1 == count) // replace all
              count = szStr;

          for(i=0; i<szStr; i++)
          {
              pos=str.find(pattern,i);

              if(std::string::npos == pos)
                  break;
              if(pos < szStr)
              {
                  std::string s=str.substr(i,pos-i);
                  retStr += s;
                  retStr += dstPattern;
                  i=pos+pattern.length()-1;
                  if(++l_count >= count)
                  {
                      i++;
                      break;
                  }
              }
          }
          retStr += str.substr(i);
          return retStr;
      }

      好,就這些了,希望對(duì)你有幫助。

        文件搜索
        (16)文件搜索
        西西軟件園提供好用的文件搜索工具,微軟自帶的文件搜索工具速度慢的令人發(fā)指,我們只能靠第三方搜索工具來搜索文件,一般的第三方文件搜索工具速度都很快,百硬盤幾十萬個(gè)文件,可以在幾秒鐘之內(nèi)完成索引,文件名搜索瞬間呈現(xiàn)結(jié)果。...更多>>

        相關(guān)評(píng)論

        閱讀本文后您有什么感想? 已有人給出評(píng)價(jià)!

        • 8 喜歡喜歡
        • 3 頂
        • 1 難過難過
        • 5 囧
        • 3 圍觀圍觀
        • 2 無聊無聊

        熱門評(píng)論

        最新評(píng)論

        發(fā)表評(píng)論 查看所有評(píng)論(0)

        昵稱:
        表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
        字?jǐn)?shù): 0/500 (您的評(píng)論需要經(jīng)過審核才能顯示)