/** * 把字符串中所有小写字母转换成大写,其余不变,不能用Stirng.toUpperCase()方法 * @author alen * */ public class Change { public static String changeStr(String str){ str.toUpperCase(); char[] ch = str.toCharArray(); StringBuffer sb = new StringBuffer(); int a = 'A'-'a'; //获得大小写之间差值 for(int i = 0; i < ch.length; i++){ if('a' <= ch[i] && ch[i] <= 'z'){ ch[i] = (char)(ch[i]+a); } sb.append(ch[i]); } return sb.toString(); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(changeStr("aAF23fqe")); } }
原文地址:http://blog.csdn.net/alen1985/archive/2010/07/07/5718689.aspx