無題

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

          統計

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

          主站蜘蛛池模板: 墨玉县| 聂拉木县| 咸丰县| 定西市| 集安市| 改则县| 南江县| 越西县| 安化县| 永善县| 龙泉市| 武川县| 玉屏| 应城市| 尉氏县| 阿瓦提县| 新闻| 和田市| 修武县| 桦甸市| 安龙县| 望都县| 宝丰县| 阿克陶县| 正镶白旗| 东源县| 荔波县| 廊坊市| 上栗县| 屏南县| 平阳县| 定陶县| 上犹县| 阳新县| 黄梅县| 吉林省| 龙岩市| 印江| 甘洛县| 义马市| 馆陶县|