Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stream Tokeniser

 
Flora Ng
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Ex.
// s is a String containing the data from the text file
StringTokenizer st = new StringTokenizer( s, "$" );
while (st.hasMoreTokens())
{
System.out.println(st.nextToken());
}
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
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Thanks...

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic