Results 1 to 3 of 3
  1. #1
    vijaygk is offline Member
    Join Date
    Jul 2008
    Posts
    2
    Rep Power
    0

    Default String tokenizing with Scanner

    Hi,

    I need tokenizing help for my problem.
    One of my application will get a huge strinG like below:

    TXR,200,1,<ABC><DEF>1</DEF><ABC>TXR,210,1,<ABC><DEF>2</DEF><ABC>TXR,220,1,<ABC><DEF>3</DEF><ABC>TXR,220,1,<ABC><DEF>4</DEF><ABC>TXR,1,0

    Here ,<ABC><DEF>1</DEF><ABC> is an example xml I have given. This may span to multiple xml elements.

    I should be able to create a string array with each string represeting like
    TXR,200,1,<ABC><DEF>1</DEF><ABC>. So here we can assume TXR as delimiter. Upon each string I have to do a lot of processing.

    When I used Scanner, I am getting tokens with indexes 0, 2, 4 but not all tokens.

    Scanner scanner = new Scanner(tranFF);
    scanner.useDelimiter("ITC");
    while (scanner.hasNext()) {
    tokens[count] = scanner.next();
    System.out.println("tokens[" + count + "]" + scanner.next());*/
    count++;
    }

    Could you please help regarding this problem

    Thanks,
    gk

  2. #2
    vijaygk is offline Member
    Join Date
    Jul 2008
    Posts
    2
    Rep Power
    0

    Smile

    Hi All,

    I got it. I did foolish mistake in while loop by doing one more next().
    One more thread in this forum caught my attention.

    I will start processing each token string.

    May be this will tempt me to do more posts.

    Thanks for your reading.

    Thanks,
    gk

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Best practice is use some dummy values, without processing on the same line at once. So you can use dummy values anywhere you want. As you said, processing on the same line can cause lots of damages, because of that you got a hack there. I'm not saying that it's wrong, but it can be bad practice in some instances.

    If you solve the problem please mark the thread solved. It's really helpful to all other members here in our community. :)

Similar Threads

  1. need help with scanner
    By whiterex in forum New To Java
    Replies: 1
    Last Post: 04-22-2008, 02:41 PM
  2. Tokenizing with Scanner
    By sireesha in forum New To Java
    Replies: 3
    Last Post: 02-05-2008, 09:44 PM
  3. Replies: 0
    Last Post: 11-20-2007, 05:59 PM
  4. help with IP scanner
    By tommy in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 09:00 PM
  5. Replies: 1
    Last Post: 08-03-2007, 11:52 AM

Posting Permissions

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