Results 1 to 2 of 2

Thread: capitals

  1. #1
    Zensai is offline Member
    Join Date
    Nov 2007
    Posts
    14
    Rep Power
    0

    Default capitals

    how can i capitalize the first letter of a string? splitting the string, giving UpperCase to the first letter and unite the two substrings? so how i do that :)

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Java Code:
    String s = "hello world";
    String[] strs = s.split("\\s");
    for(int j = 0; j < strs.length; j++) {
        String firstLetter = String.valueOf(strs[j].charAt(0));
        firstLetter = firstLetter.toUpperCase();
        strs[j] = firstLetter + strs[j].substring(1);
    }
    for(int j = 0; j < strs.length; j++)
        System.out.println(strs[j]);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •