First, it would help if you would UseCodeTags (<---that's a link) when posting your source code.
Next, if you need help, you have to ask. Tell us what the code DOES, and what you EXPECT it to do.
Finally, you may want to read our FAQ on how to get the most out of our site: HowToAskQuestionsOnJavaRanch
Guillaume Jourdan wrote:Hi,
You want to convert UTF String to ASCII String?
This piece of code does not make much sense!
First you convert a String using the ASCII encoding into a byte array, and then assume this byte array to be the platform-default encoded version of a String and fetch it.
There is no such thing like an UTF String or an ASCII String. There are Strings and they can (or can not) be represented using several encodings as byte arrays.
Ryan de Kwaadsteniet wrote:Hello, i am trying to basically take a string entered by the user, convert each character into their ASCII value, and then take that string of numbers (eg. hello = 104101108108111) and change it back to a character.
Well first, I assume this is an exercise for a class, because otherwise it's rather pointless.
If I understand you right, the first thing to understand is that BOTH forms are Strings, so I suspect that you want to convert the String "hello" to a String that contains each character of "hello" converted to its 3-digit decimal number (0-filled if need be) in String form.
There are several ways of doing it, but my suggestion would be to look at String.format().
Given a character (let's say 'h'), the expression
String.format("%03d", (int) 'h')
will return 'h's value as a decimal String with at least 3 digits (0-filled if necessary).
So a method:will return a String of the format you want.
Now see if you can put that to some use for your encryption.
you should break down your code into discrete methods. a method to read the data. A method to parse the data. A method to print data. etc.
variable should have descriptive names. what does the variable 'a' represent - apples? aardvarks? atomicWeapons? you aren't texting someone - use your keyboard and make life easy on yourself (and everyone else who is trying to help you).