首字母大小写转换

这两种都是小写转大写,都是进行scii偏移编码的方式,大写转小写同理

/**
     * 将字符串的首字母转大写
     *
     * @param str 需要转换的字符串
     * @return
     */
    private static String captureName(String str) {
        // 进行字母的ascii编码前移
        char[] cs = str.toCharArray();
        cs[0] -= 32;//大写转小写只需要改为: cs[0] += 32;即可。
        return String.valueOf(cs);
    }


    // 把一个字符串的第一个字母大写
    private static String getMethodName(String fildeName) throws Exception {
        byte[] items = fildeName.getBytes();
        items[0] = (byte) ((char) items[0] - 'a' + 'A');//大写转小写只需要改为:'A' + 'a'即可。
        return new String(items);
    }

猜你喜欢

转载自blog.csdn.net/weixin_39513166/article/details/89313771