Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: substring

  1. #1
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default substring

    Hello I'll get straight to the point, I am working on an application where I get input from the user (cmd) and send it off to a switch statement (switch(cmd)). I don't know how to explain the rest so I'll show you.

    This:
    String option1 = cmd.substring(cmd.indexOf(" ") + 1);

    Is equaling what ever the command (cmd) is. For example if I type:

    hello world

    cmd should equal "hello" and option1 should equal "world" but instead option1 equals "hello".

    String cmd = new Scanner(System.in).nextLine();


  2. #2
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: substring

    I fixed it! It was so simple

    String[] command = cmd.split(" ");

    Then just

    switch(command[0])

Similar Threads

  1. Need some help with substring please
    By iijakeh in forum Java SE APIs
    Replies: 18
    Last Post: April 7th, 2012, 09:08 AM
  2. SUBSTRING
    By cutee_eyeh in forum Object Oriented Programming
    Replies: 1
    Last Post: November 12th, 2010, 03:57 AM
  3. Substring help
    By Roach in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 21st, 2010, 08:57 AM
  4. Substring function
    By bristol580 in forum Java SE APIs
    Replies: 2
    Last Post: November 12th, 2009, 11:29 AM
  5. First string is a substring of another
    By mgutierrez19 in forum What's Wrong With My Code?
    Replies: 13
    Last Post: October 21st, 2009, 11:35 PM

Tags for this Thread