• Post Reply Bookmark Topic Watch Topic
  • New Topic

StringTokenizer output formatting  RSS feed

 
Ryan G. Jones
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Im trying to build a string tokenizer, that scans through Strings stored in a StringArray, and removes delimiters. (.,?!<> etc etc)

But using the standard ".hasMoreTokens" and ".nextToken", as with ".hasMoreElements" and ".nextElement", When i print the output, after tokenization to the console, it is removing my delimiters, but printing one token per line.

Is there any way, or a differant method to use in order to get it to print the output on one line ?

Thanks a lot

- Ryan
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Some of the class names you use are not standard names (eg StringArray, which I think means String array). You realise that StringTokenizer is described as legacy code and you are advised against using it?
You can print the Strings with the print() method of PrintStream and print " " if there are more tokens and use println() if there aren't. But you would do better to look at the regular expression API and methods of the String class like replaceXXX and split.
 
Ryan G. Jones
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Legacy code? wow, my lecturer at university has taught use to use it :S

Thanks a lot for your help
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

From the API docs of StringTokenizer
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.


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!