1. Welcome to Tacoma World!

    You are currently viewing as a guest! To get full-access, you need to register for a FREE account.

    As a registered member, you’ll be able to:
    • Participate in all Tacoma discussion topics
    • Communicate privately with other Tacoma owners from around the world
    • Post your own photos in our Members Gallery
    • Access all special features of the site

Java HELPPPPPPPPPPPPPPPPPp

Discussion in 'Technology' started by snowgod06, Oct 19, 2009.

  1. Oct 19, 2009 at 2:31 PM
    #1
    snowgod06

    snowgod06 [OP] UG legend wannabe

    Joined:
    Apr 26, 2009
    Member:
    #16454
    Messages:
    5,576
    Gender:
    Male
    First Name:
    Rob
    A farm field, OREGON
    Vehicle:
    06 Access Cab
    crap bolted and welded together....
    if anyone knows how to, please respond. I'm stuck on trying to write a simple piece that asks me to print the first 5 characters of a name

    i know how to print the first character.
    EX. firstL=first.charAT(0); so if i give the name robert, it would print the "r".

    But how would i write code to print the first 5 characters.
    thanks to anyone that can help me.
     
  2. Oct 20, 2009 at 7:49 AM
    #2
    thecoldone06

    thecoldone06 Well-Known Member

    Joined:
    Sep 20, 2007
    Member:
    #2750
    Messages:
    240
    Gender:
    Male
    could you do something like:

    Code:
    string name = 'robert';
    string firstFiveChar = name.substring(0, 4);
    
     
  3. Oct 20, 2009 at 11:38 AM
    #3
    snowgod06

    snowgod06 [OP] UG legend wannabe

    Joined:
    Apr 26, 2009
    Member:
    #16454
    Messages:
    5,576
    Gender:
    Male
    First Name:
    Rob
    A farm field, OREGON
    Vehicle:
    06 Access Cab
    crap bolted and welded together....

    oh man, your a life saver, the code worked with one minor alteration. that alteration was in defining the amount of characters in

    name.substring(0, 4);
    I had to just change the 4 to a 5 and it worked. Thanks again SOOOOOOOOOO much
     
  4. Oct 20, 2009 at 12:47 PM
    #4
    thecoldone06

    thecoldone06 Well-Known Member

    Joined:
    Sep 20, 2007
    Member:
    #2750
    Messages:
    240
    Gender:
    Male
    No problem, glad it helped :)
     

Products Discussed in

To Top