废话不多说,上代码

	/**
	 * @param source 源字符串
	 * @param target 查询的子串
	 * String 的indexOf方法查询只会返回最开始的符合目标子串的索引,后面如果也有符合的子串则不会计算在内
	 */
	public void FindString(String source,String target){
		//计数器
		int count = 0;
		//每次查询开始的位置
		int fromIndex = 0;
		while((fromIndex = source.indexOf(target, fromIndex)) != -1){
			count ++;
			fromIndex = fromIndex + target.length();
		}
		
		System.out.println(count);
	}

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-03
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2021-12-27
  • 2021-10-26
相关资源
相似解决方案