Thread: Capitalize

    #1
  1. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0

    Capitalize


    I want to take a string, and capitalize the first letter.
    How would I do that?

    Ex:

    j2309839

    to

    J2309839
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Look at String.toUpperCase() and/or Character.toUpperCase(). you could use these in conjunction with String.substring() and String.indexOf() or maybe String.toCharArray().
  4. #3
  5. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    What are their arguments?
    Also, what would you call String.toUppercase? a method? function? object?

    I'm still new to the terminology, and I didn't find any of those above in my jsp books. (Mostly cause i didn't know where too look.)
  6. #4
  7. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Bookmark this link. It is the API javadocs. You will use this more than any book.
    http://java.sun.com/j2se/1.4.1/docs/api/

    Scroll down on the left to find the Character class and the String class. When you click on these, all the constructors and methods will show in the main frame.

    String is a class. Character is a class. When you make a new one (ex: String str = "this is a string") it is called an object. What I told you to use were methods. They are called methods in Java, not functions, though they are essentially the same thing and I continually use the terms interchangeably.
  8. #5
  9. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    Could you show me some example code?
    That page doesn't have any examples, so it's quite hard for me to understand at this point
    Code:
    num = String.toUppercase("num");
    that just gives "cannon resolve symbol"
  10. #6
  11. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    No offense, but this is getting into java fundamentals. I would suggest a beginning java tutorial. A search on google should turn up many results.

    To answer your question, toUpperCase is not a static method and therefore needs to be called on a valid String object. Something like this would work:
    Code:
    num = num.toUppercase("num");
    Assuming num is a String object.

    This will all become clearer if you learn some fundamentals.

    EDIT: here is a tutorial off of Suns site
    http://java.sun.com/docs/books/tutor...ted/index.html
    Last edited by Nemi; July 1st, 2003 at 03:26 PM.
  12. #7
  13. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    num = "num".toUpperCase() will also work. num would be equal to "Num".

    Steven, since you're getting into jsp, you should probably also bookmark the j2ee javadocs: http://java.sun.com/j2ee/sdk_1.3/techdocs/api/

    It takes awhile to get comfortable using/browsing a javadoc, but once you've used it for awhile you'll find the answers to most of your questions there.
    -james

IMN logo majestic logo threadwatch logo seochat tools logo