aspose file tools*
The moose likes Performance and the fly likes String Tokenizer or Regex Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "String Tokenizer or Regex" Watch "String Tokenizer or Regex" New topic
Author

String Tokenizer or Regex

Ashwath Rangan
Greenhorn

Joined: Jan 30, 2007
Posts: 6
I need to read text from a CSV file where i use "|" as seperators. I am wondering if i should be using String Tokenizer or Regular expressions. Can any body help me in deciding wich is faster.

Thanks in advance
Arulanand Dayalan
Ranch Hand

Joined: Aug 10, 2005
Posts: 124
Regular Expression are faster.

Thanks and Regards,
Arul.
Alan Moore
Ranch Hand

Joined: May 06, 2004
Posts: 262
It doesn't matter whether StringTokenizer or split() is faster; neither one is the right tool for this job. For standard CSV data, I would recommend a dedicated CSV parser/tokenizer, but it sounds like Stephen Ostermiller's StringTokenizer replacement will suit your needs better:

http://ostermiller.org/utils/StringTokenizer.html
Chris Beckey
Ranch Hand

Joined: Jun 09, 2006
Posts: 116

If you are reading from files (as in FileInputStream() or FileReader()) then java.io.StreamTokenizer is another possibility if the parsing is reasonably simple.
 
 
subject: String Tokenizer or Regex