Converting a char to uppercase

前端 未结 10 726
南方客
南方客 2020-12-02 09:48
String lower = Name.toLowerCase();
int a = Name.indexOf(\" \",0);
String first = lower.substring(0, a);
String last = lower.substring(a+1);
char f = first.charAt(0);         


        
10条回答
  •  一个人的身影
    2020-12-02 10:06

    You can use Character#toUpperCase() for this.

    char fUpper = Character.toUpperCase(f);
    char lUpper = Character.toUpperCase(l);
    

    It has however some limitations since the world is aware of many more characters than can ever fit in 16bit char range. See also the following excerpt of the javadoc:

    Note: This method cannot handle supplementary characters. To support all Unicode characters, including supplementary characters, use the toUpperCase(int) method.

提交回复
热议问题