File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
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

wood burning stoves
subject: Stream Tokeniser