Hi, I am reading a String with "," as delimiter. I use StringTokenizer to read values from String. But there is a chance that I get no values for some tokens . eg: 111,222,,444,,666 I have a problem in reading empty tokens. StringTokenizer class is not considering empty tokens. I get output as 111 222 444 666 Is there anyway I get that null values? Please advice me. Thanks, Ram
Post by:Chad McGowan
, Ranch Hand
If you are using 1.4, look at String.split(). I think it gives you a blank space for empty tokens, but I can't remember for sure. Look at the api to be sure. Chad
Post by:John M Brown
, Ranch Hand
I ran into a similar problem using a pipe-delimeted record format using jdk1.3. The only way I was able to resolve this issue was to construct a StringTokenizer where the delimeters are also counted as tokens, and adding logic to find adjacent tokens (which have no value between them), and also for the 1st and last valuebeing null (in which the 1st or last charater of the string is also a delimeter) Here is the code I came up with.... P.S. The code actually creates a hashmap with the key being the Integer position of the token, and the value being the token.
Post by:Jim Yingst
Assorted past discussions of this topic can be found here, here, and here.
This thread has been viewed 1720 times.
All times above are in ranch (not your local) time.
The current ranch time is Sep 25, 2018 23:37:31.