• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Tokenizer Crypting.

 
Adam Polak
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone have an idea how I could do the following things with a String Tokenizer?:
1) Turn a word around, hello would become olleh for instance.
2)Use the tokenizer in a way that every letter would be shifted 3 places with in the alfabet. If the alfabet end it must continue from the start. I heard its best to use ASCII for this.
 
Greg Charles
Sheriff
Posts: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you could use a StringTokenizer in your solution, but it wouldn't give you much. It's like when the marketers of Frosted Sugarbombs cereal say it is part of a complete breakfast, and then show eggs, toast, fruit, orange juice, etc. It's there, but it's not really adding anything.
On the other hand, a StringBuffer could be very useful.
 
Adam Polak
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Well the thing is I am requested to use a Tokenizer in this one.
So if you know HOW it could be usefull please tell me because I'm going crazy over this one
 
Adam Polak
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just used the Tokenizer to keep things going while the word still has more chars, but now I need to knw how to turn those chars around (hello to olleh)
StringTokenizer reverseString = new StringTokenizer (word, "");
while (reverseString.hasMoreTokens()) {

}
This is what I got so far..
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see no reasonable way to use a StringTokenizer with this problem.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using an empty String as the list of delimiters won't break a String up into seperate characters - it will simply treat the entire String as one token.
You could use String.charAt(int) to get a single character from teh String.
You could use a StringBuffer to reverse the characters.
I really doubt you'll have much success creating a reasonable solution using StringTokenizer.
 
Adam Polak
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I only use it for the hasMoreTokens method now...the only thing I have to know is how to reverse the word...
 
Les Hayden
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the string you have to work with only contain one word, or a list of words like a sentence?
 
Adam Polak
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only one word
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic