我的Java路上那些事兒
快樂(lè)成長(zhǎng)
posts - 110, comments - 101, trackbacks - 0, articles - 7
BlogJava
::
首頁(yè)
::
新隨筆
::
聯(lián)系
::
聚合
::
管理
取得指定子串在字符串中出現(xiàn)的次數(shù)
Posted on 2011-05-26 13:51
云云
閱讀(1758)
評(píng)論(0)
編輯
收藏
/** */
/**
* 取得指定子串在字符串中出現(xiàn)的次數(shù)。
* <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
子串在字符串中出現(xiàn)的次數(shù),如果字符串為<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;
}
新用戶注冊(cè)
刷新評(píng)論列表
只有注冊(cè)用戶
登錄
后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問(wèn)
管理
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
常用鏈接
我的隨筆
我的評(píng)論
我的參與
最新評(píng)論
留言簿
(9)
給我留言
查看公開(kāi)留言
查看私人留言
隨筆檔案
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)
搜索
最新評(píng)論
1.?re: CAP原理與最終一致性 強(qiáng)一致性 透析
學(xué)習(xí)。
--NewSea
2.?re: 一致性哈希算法與Java實(shí)現(xiàn)
有一個(gè)問(wèn)題,如果使用虛擬節(jié)點(diǎn),某臺(tái)機(jī)器每次宕機(jī)再恢復(fù)后都需要遷移數(shù)據(jù)。這樣是否反而更麻煩了。
--三單聯(lián)咖啡色
3.?re: java static塊和static 方法 的使用區(qū)別
sss
--zhangsan
4.?re: struts2 jsp頁(yè)面使用s:if 標(biāo)簽
你是基佬 哦耶耶
--基佬
5.?re: android開(kāi)發(fā)過(guò)程中 R文件消失 clean 和 build project都無(wú)效 已解決
評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
--llll
閱讀排行榜
1.?linux 新建用戶、用戶組 以及為新用戶分配權(quán)限(127905)
2.?Oracle內(nèi)連接、外連接、右外連接、全外連接小總結(jié)(93213)
3.?zookeeper 集群安裝(單點(diǎn)與分布式成功安裝)摘錄(79165)
4.?android開(kāi)發(fā)過(guò)程中 R文件消失 clean 和 build project都無(wú)效 已解決(76982)
5.?一致性哈希算法與Java實(shí)現(xiàn) (48862)
評(píng)論排行榜
1.?Oracle內(nèi)連接、外連接、右外連接、全外連接小總結(jié)(12)
2.?zookeeper 集群安裝(單點(diǎn)與分布式成功安裝)摘錄(11)
3.?android開(kāi)發(fā)過(guò)程中 R文件消失 clean 和 build project都無(wú)效 已解決(6)
4.?struts2 jsp表單提交后保留表單中輸入框中的值 下拉框select與input(6)
5.?jquery 自動(dòng)過(guò)濾表單輸入框前后空格(5)
主站蜘蛛池模板:
宝清县
|
遵义市
|
石台县
|
化隆
|
社会
|
扬中市
|
宣恩县
|
瑞丽市
|
民勤县
|
宣武区
|
山西省
|
德兴市
|
桐城市
|
五原县
|
西丰县
|
神池县
|
伊春市
|
云龙县
|
武陟县
|
高淳县
|
无极县
|
崇信县
|
皮山县
|
西昌市
|
绥化市
|
观塘区
|
从化市
|
巴林右旗
|
榆中县
|
吉安市
|
沁水县
|
望城县
|
墨竹工卡县
|
仲巴县
|
桐乡市
|
芦溪县
|
泸水县
|
彰化市
|
富川
|
呈贡县
|
江华
|