import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* @Description
* @author Lazy-G
* @version
* @Date 2021-01-13 14:15:14
*
*/
public class KT16 {
public static void main(String[] args) {
//统计字符串有多少个字母
String str = "abc124";
Pattern p = Pattern.compile("[a-z]",2); //正则表达式 2:不区分大小写
Matcher m = p.matcher(str);
int n =0;
while (m.find()) ++n;
System.out.println(n);
}
《java入门》统计字符串字母
最新推荐文章于 2023-08-04 15:14:34 发布