Java中 获取指定字符串在另一个字符串中出现的次数,供大家参考,具体内容如下 public static void main(String[] args) { String srcText = "Hello World"; St
Java中 获取指定字符串在另一个字符串中出现的次数,供大家参考,具体内容如下
public static void main(String[] args) { String srcText = "Hello World"; String findText = "e"; int num = appearNumber(srcText, findText); System.out.println(num); } public static int appearNumber(String srcText, String findText) { int count = 0; Pattern p = Pattern.compile(findText); Matcher m = p.matcher(srcText); while (m.find()) { count++; } return count; }
--结束END--
本文标题: Java获取指定字符串出现次数的方法
本文链接: https://www.lsjlt.com/news/220368.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0