Make the next character of a space as capital
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
Capitalize First Char of Each Word in a String Java
号
我有一个字符串
型
1 2 3 4 5 | System.out.println( org.apache.commons.lang.WordUtils.capitalize( "yellow fox jumped over brown foot" ) ); |
输出:
1 | Yellow Fox Jumped Over Brown Foot |
号
型
您可以使用来自acl的wordutils类的capitalize方法。
型
这可能不是最有效的,但可能会给您一个起点:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public String capitalize(String original) { String[] parts = original.split(""); StringBuffer result = new StringBuffer(); for (String part : parts) { String firstChar = part.substring(0, 1).toUpperCase(); result.append(firstChar + part.substring(1)); result.append(""); } String capitalized = result.toString(); return capitalized.substring(0, capitalized.length()-1); } |