How bout this?
Tokens.java
import java.io.*;
import java.util.*;
class Tokens
{
public static void main(String[] args)
{
int count=0;
String array[]= new String[100];
StringTokenizer st = new StringTokenizer("Diablo & generals|RPG|PG|PS2|20","|");
while (st.hasMoreTokens())
{
//System.out.println(st.nextToken());
array[count] =st.nextToken();
count++;
}
System.out.print(array[0]); //change here to see different token
}
}
[IMG]http://img476.imageshack.us/img476/5171/cut20ln.png[/IMG]
Piworld ™
[Tis simple as Pie]
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
<strong>String line = "C&C Generals|Real Time Strategy|PG|PS2|20";</strong>
<strong>String[] tokens = line.split("|");</strong>
<strong>for (int i=0;i<tokens.length;i++)</strong>
<strong> System.out.println(tokens[i]);</strong>
Phaelax
Practically a Posting Shark
858 posts since Mar 2004
Reputation Points: 92
Solved Threads: 51
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
That link makes some valid points about initialization costs. I find splitString easier to use though, and it does more than just search for delimiters, its parameter is actually a regular expression. The regex search could possibly slow the parsing down a bit, but I'm not sure by how much or how much it would even take to be noticable.
Phaelax
Practically a Posting Shark
858 posts since Mar 2004
Reputation Points: 92
Solved Threads: 51
give me the sample output that you want to be output
It has been 2 years since the last post. You think that the OP was waiting for you?
If you really want to help someone then why don't you try the most recent posts?
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448