Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Post Converting first character of String variable to capital.

    Hello there,
    I've been learning about Java for a while now, and have a bit of a problem I'm not even sure can be solved.
    I'm making a quick text based game for a friend who writes the story, but can't write the code. I am hoping to have a part where the player enters their name using Scanner and next String. Is it possible to have the Name variable ignore all case and then capitalise only the first letter of each word (separated by a space).
    For example player enters:
    'bob jones'
    'BOB JONES'
    etc.
    The Name variable will be set to 'Bob Jones' and nothing else.
    Thanks for any help,
    ~Longeye~

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,513
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Augustus Longeye View Post
    Hello there,
    I've been learning about Java for a while now, and have a bit of a problem I'm not even sure can be solved.
    I'm making a quick text based game for a friend who writes the story, but can't write the code. I am hoping to have a part where the player enters their name using Scanner and next String. Is it possible to have the Name variable ignore all case and then capitalise only the first letter of each word (separated by a space).
    For example player enters:
    'bob jones'
    'BOB JONES'
    etc.
    The Name variable will be set to 'Bob Jones' and nothing else.
    Thanks for any help,
    ~Longeye~
    So a 'first character of a word' is either the first character in the String or it is preceded by a white space character. Have a look at the Character class. It has lots of static boolean methods that classify the type of character, i.e. white space, letters etc. Also read the API documentation of the available methods in the String class.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Removing last character from a String
    By newToJava3 in forum New To Java
    Replies: 2
    Last Post: 11-28-2010, 12:43 AM
  2. Converting a File Format Variable To String
    By AJArmstron@aol.com in forum New To Java
    Replies: 4
    Last Post: 04-15-2010, 09:48 PM
  3. Replies: 7
    Last Post: 10-12-2009, 11:16 PM
  4. how to get next character/string
    By doha786 in forum New To Java
    Replies: 3
    Last Post: 03-28-2009, 04:04 AM
  5. Replies: 2
    Last Post: 08-27-2008, 02:40 PM

Tags for this Thread

Posting Permissions

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