Results 1 to 10 of 10

Thread: Parsing Delimited Strings

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member rockies1's Avatar
    Join Date
    Jul 1999
    Location
    Stuck at work
    Posts
    375

    Resolved Parsing Delimited Strings

    I use the follwing method to parse delimited strings so I can get certain pieces:
    Code:
     public static String instanceSearch(String strIn, int intInstance, String strDelimiter)
     {
      String strToReturn = "";
      StringTokenizer t = new StringTokenizer(strIn,strDelimiter);
      int intCounter = 0;
      while(t.hasMoreTokens())
      { 
       intCounter++;
       if(intCounter == intInstance)
       {
        strToReturn =  t.nextToken().toString();
        continue;
       }
       t.nextToken();
      }
      return strToReturn; 
     }//End instanceSearch
    I call it using:
    strBAN = instanceSearch(strLineIn,4,",");
    This means I want the fourth item in the comma-delimeted string I call strLineIn.
    For this string:
    123,Bedon,Joe,21 ROCK PILE,NUEVO,CA,925679086,111,100.00,07/07/2005,1676268503
    I would return 21 ROCK PILE

    For this string:
    456,,,62 RIVERSIDE PLAZA,Podunk,NM,871204306,111,81.00,06/30/2005,1675376520
    I return NM

    I can not figure out why it is skipping the 2 empty items after the 456.

    Anyone have an idea?
    Last edited by rockies1; Jul 26th, 2005 at 08:46 AM. Reason: Closing
    Morgan
    teamtj@gmail.com - Home
    morgan.erickson@sprint.com - Work
    Using VB6 SP6 but trying to learn VB2005EE

Posting Permissions

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



Click Here to Expand Forum to Full Width