Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Tokenizer or Regex

 
Ashwath Rangan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regular Expression are faster.

Thanks and Regards,
Arul.
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are reading from files (as in FileInputStream() or FileReader()) then java.io.StreamTokenizer is another possibility if the parsing is reasonably simple.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic