• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

catching null in a StringTokenizer

 
swatione chowdary
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can any one give me the solution on this

i have a situation like this ,

i have a String like this

~~~~data~~~name~~~~hi~how~are~you~

where '~' is a delimeter.

i passed this string in to a StringTokenizer

in a StringTokenizer object if two delimeters are adjacent i have to consider it as null token.

as the methods( nextToken() , nextElement() ) in StringTokenizer are not returning null.

how can i achieve it even through programmetically.

can any one give this logic.
 
Kaydell Leavitt
Ranch Hand
Posts: 689
Eclipse IDE Firefox Browser Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe it's giving you an empty string instead of a null object-reference variable.

Compare the results against the empty String: ""

Kaydell
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the "other" constructor on StringTokenizer. You can tell it to return the delimiters and the data. It can be a bit tricky to use the results. Show us what you make!
 
swatione chowdary
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hear is the code for this problem, you can ask questions where you cant understand.

i request every one to post the solutions like this.

the code which is in the while is the actual code for the question raised.

i invite your comments.


i think that it is not possible to do with the two previous replyes.





[edit - added code tags and broke long line]
[ June 27, 2007: Message edited by: David O'Meara ]
 
dhwani mathur
Ranch Hand
Posts: 621
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok,I dont know if i am clear with your "actual doubt" but,
below shown is the link i hope it can help you to solve your problem .


http://forum.java.sun.com/thread.jspa?threadID=419339&messageID=1866816
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure all of the code is required, a comment like "check the API for StringTokenizer will help, specifically the constructor that accepts a boolean".

Viola, solved
 
bart zagers
Ranch Hand
Posts: 234
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know even the modern String.split does the trick (giving empty strings instead of null's).
 
Bill Cruise
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This test code shows the difference between a StringTokenizer object and the String split() method.



I think in your case you want to split() the input String.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic