67,512
社区成员
发帖
与我相关
我的任务
分享
String str = "aabbCCdd";
String str = "aabbCCdd";
if (str.matches(".*[A-Z].*"))
System.out.println("此字符串包含大写字母。");
else
System.out.println("此字符串不包含大写字母。");
System.out.println(str.replaceAll("[A-Z]", "!"));
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class JudgeUpperOrLower {
public static void main(String[] args) {
String str="aabbCCdd";
Matcher m=Pattern.compile("[A-Z]").matcher(str);
while(m.find()) {
System.out.println(m.group()+"---"+m.start()+"---"+m.end());
}
}
}
C---4---5
C---5---6