jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Stream Tokeniser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Stream Tokeniser" Watch "Stream Tokeniser" New topic

Stream Tokeniser

Flora Ng

Joined: Jul 05, 2001
Posts: 11
How do I get a number from the text file that filters out non-digit elements and punctuations using Stream Tokeniser? So for example: -$6,234.56 will gives 6234.56
Thanks in advance
Guy Reynolds
Ranch Hand

Joined: Oct 27, 2000
Posts: 61
Not enough info concerning the text file you are trying to parse...
However, if "$"'s are the only things seperating the data, ie. the data looks like $6,234.56$2,200.00$200.00, then use the "$"'s as delimeters.
// s is a String containing the data from the text file
StringTokenizer st = new StringTokenizer( s, "$" );
while (st.hasMoreTokens())
You can remove the commas or other unwanted punctuation with simple String manipulation, on each token, or on the entire String before you tokenize it.
If this is not a solution to your problem, please supply more detail about the text file in question and how you want the data to look when you are done with it.

[This message has been edited by Guy Reynolds (edited July 17, 2001).]
[This message has been edited by Guy Reynolds (edited July 17, 2001).]
Flora Ng

Joined: Jul 05, 2001
Posts: 11
Thanks for your reply.
The data in the text file is delimit by spaces. Basically the program asks the user to enter the name of the text file, it then scan the content and extract numbers from that file. I want it to filter out the non-digit elements using Stream Tokenizer. So with the following text:
I wish I can earn $1,000,000 a year!
The program will return 1000000

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Stream Tokeniser
It's not a secret anymore!