• Post Reply Bookmark Topic Watch Topic
  • New Topic

StringTokenizer  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hallo,

I am reading lines from a file breaking it into tokens using StringTokenizer. I am using the delimiter ";".
In the file there are occurences of ";;". StringTokenizer does not create a token for this sequence. However it does create
a token for "; ;". Is there an easy way I can make StringTolenizer interpret ";;" as the token "" (Empty string) ?
I would like to avoid having to consider the delimiter as a token and then make code that checks if teo tokens in a row is equal to the delimiter.
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the JavaDoc about the StringTokenizer class...

JavaDoc wrote:StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.


The split() method doesn't have this issue. It will give you a blank token for double delimiters.

Henry
 
Reiner Herman
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. Very useful answer.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!