• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String Tokenizer Crypting.

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only one word
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic