無題

          拿個學位是騙自己的。學問是一輩子的。

          統計

          留言簿(3)

          閱讀排行榜

          評論排行榜

          統計給定字符串在指定字符串中出現的次數(C++源代碼)

           1//#include <iostream>
           2//統計substr在str中出現的次數并返回
           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}
          這是今天參考網上一個人的代碼修改完善的。

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

          主站蜘蛛池模板: 科尔| 靖西县| 天峻县| 米脂县| 巩义市| 枣阳市| 六盘水市| 庄浪县| 土默特左旗| 资源县| 宁远县| 会东县| 岱山县| 循化| 崇信县| 灵山县| 周宁县| 井陉县| 弋阳县| 安康市| 菏泽市| 施甸县| 柏乡县| 防城港市| 天津市| 六安市| 石门县| 西充县| 平泉县| 辉县市| 郁南县| 潞西市| 扎囊县| 礼泉县| 渝北区| 镇雄县| 许昌县| 和龙市| 金平| 湛江市| 响水县|