Converting a char to uppercase

前端 未结 10 629
南方客
南方客 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:14

    The easiest solution for your case - change the first line, let it do just the opposite thing:

    String lower = Name.toUpperCase ();
    

    Of course, it's worth to change its name too.

    0 讨论(0)
  • 2020-12-02 10:15

    If you are including the apache commons lang jar in your project than the easiest solution would be to do:

    WordUtils.capitalize(Name)
    

    takes care of all the dirty work for you. See the javadoc here

    Alternatively, you also have a capitalizeFully(String) method which also lower cases the rest of the characters.

    0 讨论(0)
  • 2020-12-02 10:22

    You can apply the .toUpperCase() directly on String variables or as an attribute to text fields. Ex: -

    String str;
    TextView txt;
    
    str.toUpperCase();// will change it to all upper case OR
    txt.append(str.toUpperCase());
    txt.setText(str.toUpperCase());
    
    0 讨论(0)
  • 2020-12-02 10:28
    f = Character.toUpperCase(f);
    l = Character.toUpperCase(l);
    
    0 讨论(0)
提交回复
热议问题