我似乎无法让StringUtils.capitalize实际将整个单词字符串大写。
我尝试了各种方法,但最终还是遇到了句子类型的情况。我尝试在要打印的内容中使用StringUtils.capitalize,但这也不起作用。我抬头也没有任何帮助。
File file =
new File("C:\\Users\\mikek\\Desktop\\name.txt");
BufferedReader abc = new BufferedReader(new FileReader(file));
List<String> data = new ArrayList<String>();
String s;
String t;
while((s=abc.readLine()!=null) {
data.add(s);
System.out.println("public static final Block " + s.toUpperCase() + " = new "
+ StringUtils.capitalize(s).replace("_","") + "(\"" + s + "\", Material.ROCK);");
}
abc.close();
}
预期:木炭块
得到了:木炭块
最佳答案
这个怎么样??
String s = "camel case word";
String camelCaseSentence = "";
String[] words = s.split(" ");
for(String w:words){
camelCaseSentence += w.substring(0,1).toUpperCase() + w.substring(1) + " ";
}
camelCaseSentence = camelCaseSentence.substring(0, camelCaseSentence.length()-1);
System.out.println(camelCaseSentence);
关于java - 如何使用StringUtils获取UpperCamelCase?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57333461/