aspose file tools
The moose likes Java in General and the fly likes How to count no. of tokens? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How to count no. of tokens?" Watch "How to count no. of tokens?" New topic
Author

How to count no. of tokens?

Anu satya
Ranch Hand

Joined: Mar 17, 2005
Posts: 146
Hello all,

I have a csv file. I am reading each line from this and writing to another file. I am doing it using StringTokenizer.
My problem is:
I wanted to count no of tokens in a string. IF number of tokens in a particular row is less than 19, some error message has to be displayed.
I thought of using String.split()
but, i am not sure, like which class i should import to do the same.

Can any one guide me in this regard!

thanks in advance


With Regards,
Anu
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
You said you are using StringTokenizer. Does it have any method to count tokens?
StringTokenizer's API page contains this instruction:

StringTokenizer is a legacy class that is retained for compatibility reasons
although its use is discouraged in new code. It is recommended that anyone
seeking this functionality use the split method of String or the
java.util.regex package instead.

Have you investigated String's split method? Have you checked out package java.util.regex?
I suggest you do these three things, in that order.


There is no emoticon for what I am feeling!
Anu satya
Ranch Hand

Joined: Mar 17, 2005
Posts: 146
Thanks Jeff.

I got the solution.

 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to count no. of tokens?
 
Similar Threads
StringTokenizer
using tokens in struts
Text to tokens?
Collections,HashSet
for loop error