File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes String Tokenizer Crypting. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String Tokenizer Crypting." Watch "String Tokenizer Crypting." New topic
Author

String Tokenizer Crypting.

Adam Polak
Greenhorn

Joined: Oct 28, 2002
Posts: 23
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

Joined: Oct 01, 2001
Posts: 2851
    
  11

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

Joined: Oct 28, 2002
Posts: 23

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

Joined: Oct 28, 2002
Posts: 23
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

Joined: Dec 10, 2001
Posts: 7023
I see no reasonable way to use a StringTokenizer with this problem.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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

Joined: Oct 28, 2002
Posts: 23
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

Joined: Jun 19, 2002
Posts: 28
Does the string you have to work with only contain one word, or a list of words like a sentence?


Les Hayden
Adam Polak
Greenhorn

Joined: Oct 28, 2002
Posts: 23
Only one word
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String Tokenizer Crypting.