java 将字符串变成小写 单引号内的字符串大小写不变
public static void main(String[] args) { String str = "asdfFFFSSDAF'aaaaAAA','132213'"; System.out.println(str.toLowerCase()); String newStr = ""; boolean flag = false; for (int i = 0; i < str.length(); i++) { if ("'".equals(str.substring(i, i + 1))) { flag = !flag; } if (flag == false) { newStr = newStr + str.substring(i, i + 1).toLowerCase(); }else{ newStr = newStr + str.substring(i, i + 1); } } System.out.println(newStr); }
输出:
asdffffssdaf'aaaaaaa','132213'
asdffffssdaf'aaaaAAA','132213'