我需要写用户在其中输入对象的字符串,如“HelloIamYourNeighbor” 并返回“你好,我是你的邻居”程序插入空白
到目前为止,我已经能够将大写字母转换为大写字母,但我无法在大写字母之间插入空格。
for (int i = 0; i < input.length(); i++) {
if (input.contains("(?=\\p{Lu})")) {
str.append(" ");
}
if (Character.isUpperCase(input.charAt(i)) && i != 0) {
str.setCharAt(i, Character.toLowerCase(input.charAt(i)));
}
}
System.out.println(str);
这可能是帮助http://stackoverflow.com/questions/4886091/insert-space-after-capital-letter?rq=1 –