無題

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

          統計

          留言簿(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 閱讀(1409) 評論(0)  編輯  收藏 所屬分類: My Program

          主站蜘蛛池模板: 浠水县| 宝鸡市| 昂仁县| 页游| 永年县| 石家庄市| 抚宁县| 自治县| 蒙城县| 贵州省| 揭阳市| 衡阳市| 茌平县| 丽水市| 南汇区| 赤城县| 邻水| 新泰市| 元江| 永福县| 阿城市| 敖汉旗| 彰化县| 义乌市| 壶关县| 新密市| 黄石市| 曲水县| 德清县| 鹤壁市| 石嘴山市| 莱州市| 景谷| 南平市| 桐柏县| 玉林市| 仁寿县| 西充县| 邵武市| 常宁市| 胶南市|