無題

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

          統計

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

          主站蜘蛛池模板: 长乐市| 江西省| 个旧市| 通城县| 高雄县| 宜川县| 黎城县| 陵水| 吉林省| 家居| 林周县| 利川市| 莱州市| 静海县| 陇西县| 瑞金市| 山东| 湖南省| 蒙城县| 福贡县| 胶州市| 宁武县| 工布江达县| 岳普湖县| 广丰县| 镇康县| 景泰县| 林口县| 九寨沟县| 江华| 中卫市| 合作市| 易门县| 纳雍县| 来凤县| 德州市| 山西省| 柏乡县| 三台县| 兖州市| 三门峡市|