無題

          拿個學(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

          主站蜘蛛池模板: 康马县| 乐平市| 仲巴县| 菏泽市| 重庆市| 吉水县| 大宁县| 墨竹工卡县| 雅安市| 屯门区| 双鸭山市| 和政县| 泗阳县| 遂宁市| 临城县| 建昌县| 平泉县| 绍兴市| 鄂托克旗| 博野县| 包头市| 瓮安县| 邵武市| 河南省| 贡山| 永兴县| 界首市| 隆尧县| 荔浦县| 枣阳市| 奇台县| 江油市| 扎鲁特旗| 筠连县| 巴马| 磐安县| 仁怀市| 巴里| 克东县| 扶沟县| 奎屯市|