java字符串中英文与数字分离,如何解决
1个回答
展开全部
String str ="4f65a45f4a54dfaF4E8465D4FA8E46";
String n="";
String sa="";
String sA="";
char a[]=str.toCharArray();
for (int i = 0; i < a.length; i++) {
int num = (int)a[i];
if(num>=48&&num<=57) {
//数字
n += a[i]+",";
}else if(num>=97&&num<=122) {
//小写字母
sa += a[i]+",";
}else if(num>=65&&num<=90) {
//大写字母
sA += a[i]+",";
}
}
String[] strNum = n.split(",");
String[] stra = sa.split(",");
String[] strA = sA.split(",");
//数字
for (String s : strNum) {
System.out.print(s);
}
System.out.println();
//小写字母
for (String s : stra) {
System.out.print(s);
}
System.out.println();
//大写字母
for (String s : strA) {
System.out.print(s);
}
---------如果可以,望采纳!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询