-
Jul 25th, 2005, 01:47 PM
#1
Thread Starter
Hyperactive Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|