根据下划线判断,转换下划线以后字符串变为大写!

char[] charArray = reportType.toCharArray();
// A-Z 对应数字65-90 a-z 对应数字97-122
for (int i = 0; i < charArray.length; i++) {
    if (charArray[i] == '_') {
        // 字符在97-122之间的都是小写字母,在原基础上加32转换成大写
        if (charArray[i + 1] >= 97 && charArray[i + 1] <= 122) {
            int upper = charArray[i + 1] - 32;
            charArray[i + 1] = (char) upper;
        }
        if (charArray[i - 1] >= 97 && charArray[i - 1] <= 122) {
            int upper = charArray[i - 1] - 32;
            charArray[i - 1] = (char) upper;
        }
    }
}
StringBuffer stringbuffer = new StringBuffer("");
for (int i = 0; i < charArray.length; i++) {
    stringbuffer .append(charArray[i]);
}
System.out.println("===="+stringbuffer +"=======");

你可能感兴趣的:(学习)