Results 1 to 5 of 5

Thread: String spliting

  1. #1
    emma is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default String spliting

    Hello,

    I am new in java, I wanna split a string like : " abc, def, ghi" and store each of tokens that I can compare token1 (abc) with token2 (def), and again compare token2 (def) with token3(ghi) until it gets the end of the file.

    any comments?

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: String spliting

    Go for it! We won't do that for you. Ask specific questions, format your code, include compilation and runtime errors.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    emma is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default Re: String spliting

    here is my code:


    public static void main(String[] args) {
    String str = "abc, def, ghi";


    System.out.println("---- Split by comma ',' ------");
    StringTokenizer st2 = new StringTokenizer(str, ",");


    //when there are still more tokens, place it in the array:

    while(st2.hasMoreTokens()) {
    String key = st2.nextToken();

    System.out.println(key );
    }



    }

    is that clear enough?

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: String spliting

    Yes, but you didn't format your code and you didn't ask a question.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #5
    viren2727in is offline Member
    Join Date
    Jan 2013
    Location
    INDIA
    Posts
    18
    Rep Power
    0

    Default Re: String spliting

    Hi emma,

    It may help you.

    [ spoonfeeding code deleted - mod ]
    Last edited by JosAH; 01-28-2013 at 04:21 PM.

Similar Threads

  1. Spliting intgers 07:34
    By yosi199 in forum New To Java
    Replies: 22
    Last Post: 03-10-2011, 03:05 AM
  2. Spliting Large String Data (upto 2 GB)
    By piyush@java in forum Advanced Java
    Replies: 5
    Last Post: 01-12-2011, 02:23 PM
  3. Spliting a string (45 Characters)
    By BobAmin in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 11-20-2010, 09:45 AM
  4. spliting a string and checking each token's format
    By Implode in forum New To Java
    Replies: 1
    Last Post: 10-18-2009, 08:41 PM
  5. Spliting desktop
    By nagarte in forum AWT / Swing
    Replies: 5
    Last Post: 05-05-2008, 12:56 PM

Posting Permissions

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