無題

          拿個學(xué)位是騙自己的。學(xué)問是一輩子的。

          統(tǒng)計

          留言簿(3)

          閱讀排行榜

          評論排行榜

          統(tǒng)計給定字符串在指定字符串中出現(xiàn)的次數(shù)(C++源代碼)

           1//#include <iostream>
           2//統(tǒng)計substr在str中出現(xiàn)的次數(shù)并返回
           3int CountSubString(std::string const& str, std::string const& substr){
           4  int nCount = 0;
           5  std::string::size_type substrSize = substr.size();
           6  std::string::size_type IndexOfFind = 0;
           7  IndexOfFind = str.find(substr, IndexOfFind);
           8  while (IndexOfFind!=std::string::npos) {
           9    ++nCount;
          10    if (substrSize>1){
          11      IndexOfFind+=substrSize;
          12    }

          13    else{
          14      ++IndexOfFind;
          15    }

          16    IndexOfFind = str.find(substr, IndexOfFind);
          17  }

          18  return nCount;
          19}
          這是今天參考網(wǎng)上一個人的代碼修改完善的。

          posted on 2007-12-05 18:26 閱讀(1410) 評論(0)  編輯  收藏 所屬分類: My Program

          主站蜘蛛池模板: 罗源县| 横峰县| 闸北区| 青川县| 平遥县| 都匀市| 大庆市| 于都县| 通江县| 白河县| 康马县| 临沧市| 丰原市| 祁连县| 多伦县| 乌拉特后旗| 监利县| 江阴市| 平乡县| 富平县| 东乡县| 宣武区| 金塔县| 达州市| 泗阳县| 中西区| 马尔康县| 望江县| 乌什县| 平度市| 湾仔区| 望奎县| 禄丰县| 乌审旗| 平果县| 万山特区| 丰镇市| 大同县| 天津市| 长岭县| 岳西县|