我的Java路上那些事兒
快樂成長
posts - 110, comments - 101, trackbacks - 0, articles - 7
BlogJava
::
首頁
::
新隨筆
::
聯系
::
聚合
::
管理
取得指定子串在字符串中出現的次數
Posted on 2011-05-26 13:51
云云
閱讀(1758)
評論(0)
編輯
收藏
/** */
/**
* 取得指定子串在字符串中出現的次數。
* <p/>
* <p>
* 如果字符串為<code>null</code>或空,則返回<code>0</code>。
* <pre>
* StringUtil.countMatches(null, *) = 0
* StringUtil.countMatches("", *) = 0
* StringUtil.countMatches("abba", null) = 0
* StringUtil.countMatches("abba", "") = 0
* StringUtil.countMatches("abba", "a") = 2
* StringUtil.countMatches("abba", "ab") = 1
* StringUtil.countMatches("abba", "xxx") = 0
* </pre>
* </p>
*
@param
str 要掃描的字符串
*
@param
subStr 子字符串
*
@return
子串在字符串中出現的次數,如果字符串為<code>null</code>或空,則返回<code>0</code>
*/
public
static
int
countMatches(String str, String subStr)
{
if
((str
==
null
)
||
(str.length()
==
0
)
||
(subStr
==
null
)
||
(subStr.length()
==
0
))
{
return
0
;
}
int
count
=
0
;
int
index
=
0
;
while
((index
=
str.indexOf(subStr, index))
!=
-
1
)
{
count
++
;
index
+=
subStr.length();
}
return
count;
}
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
Powered by:
BlogJava
Copyright © 云云
日歷
<
2011年5月
>
日
一
二
三
四
五
六
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(9)
給我留言
查看公開留言
查看私人留言
隨筆檔案
2015年7月 (1)
2014年9月 (3)
2014年1月 (3)
2013年12月 (1)
2013年11月 (4)
2013年10月 (2)
2013年7月 (2)
2013年6月 (3)
2013年4月 (2)
2013年1月 (2)
2012年12月 (4)
2012年11月 (3)
2012年10月 (3)
2012年9月 (2)
2012年8月 (1)
2012年7月 (9)
2012年6月 (2)
2012年5月 (6)
2012年4月 (7)
2012年3月 (2)
2012年2月 (1)
2012年1月 (1)
2011年12月 (2)
2011年11月 (16)
2011年10月 (7)
2011年8月 (1)
2011年6月 (2)
2011年5月 (5)
2011年4月 (9)
2011年3月 (10)
搜索
最新評論
1.?re: CAP原理與最終一致性 強一致性 透析
學習。
--NewSea
2.?re: 一致性哈希算法與Java實現
有一個問題,如果使用虛擬節點,某臺機器每次宕機再恢復后都需要遷移數據。這樣是否反而更麻煩了。
--三單聯咖啡色
3.?re: java static塊和static 方法 的使用區別
sss
--zhangsan
4.?re: struts2 jsp頁面使用s:if 標簽
你是基佬 哦耶耶
--基佬
5.?re: android開發過程中 R文件消失 clean 和 build project都無效 已解決
評論內容較長,點擊標題查看
--llll
閱讀排行榜
1.?linux 新建用戶、用戶組 以及為新用戶分配權限(127905)
2.?Oracle內連接、外連接、右外連接、全外連接小總結(93213)
3.?zookeeper 集群安裝(單點與分布式成功安裝)摘錄(79165)
4.?android開發過程中 R文件消失 clean 和 build project都無效 已解決(76982)
5.?一致性哈希算法與Java實現 (48862)
評論排行榜
1.?Oracle內連接、外連接、右外連接、全外連接小總結(12)
2.?zookeeper 集群安裝(單點與分布式成功安裝)摘錄(11)
3.?android開發過程中 R文件消失 clean 和 build project都無效 已解決(6)
4.?struts2 jsp表單提交后保留表單中輸入框中的值 下拉框select與input(6)
5.?jquery 自動過濾表單輸入框前后空格(5)
主站蜘蛛池模板:
亚东县
|
卫辉市
|
阳江市
|
三穗县
|
临湘市
|
乌兰浩特市
|
邮箱
|
永春县
|
武邑县
|
靖江市
|
昭觉县
|
同德县
|
襄汾县
|
南宫市
|
洪江市
|
瑞安市
|
浑源县
|
三江
|
通渭县
|
东乡
|
赫章县
|
商城县
|
化德县
|
花莲县
|
平武县
|
东台市
|
成都市
|
沛县
|
夹江县
|
库伦旗
|
龙门县
|
阿勒泰市
|
绥江县
|
永清县
|
汨罗市
|
团风县
|
临潭县
|
昌平区
|
嘉定区
|
成都市
|
岳阳县
|