便捷的查找多个相连字符在一串字符串中出现次数

xiaoxiao2021-02-28  44

public class b { public static void main(String[] args) { String str1 = "dsasdsadsdsdvgcsds"; String str2 = "ds"; //定义一个计数器count int count = 0; for (String tmp = str1; tmp != null && tmp.length() >= str2.length(); tmp = tmp.substring(1)) { if (tmp.indexOf(str2) == 0) { count++; } } System.out.println("ds出现的次数" + count); } }

转载请注明原文地址: https://www.6miu.com/read-2625165.html

最新回复(0)