• Post Reply Bookmark Topic Watch Topic
  • New Topic

StringTokenizer  RSS feed

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a String; for example, Citizen Action: Salvation Army~6

The '~' is the delimiter.

And I want to use the java.util.StringTokenizer to get two tokens: one is the 'Citizen Action: Salvation Army' and the other is the '6'. And then convert '6' back to an Int.

I am calling a TokenUtil class to do the job

TokenUtil.getTokens( stringToBeParsed );

Pass the stringToBeParsed and get two tokens back.

 
Scott Dunbar
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, first, if at all possible, use the String.split() method. The StringTokenizer is kinda deprecated. However, if that is not possible (you need to compile/run in a 1.3 or less environment), you'll do something like:



If you are not running in the same class you will need to add get methods for the static variables.
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the j2sdk1.4.2 in my machine. How to I use the String.split() method? Thanks again for help.
 
Scott Dunbar
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The above would look something like:

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!