Computer Science Canada Help with conversion program |
Author: | Azzy [ Sat Mar 26, 2005 12:41 pm ] | ||
Post subject: | Help with conversion program | ||
I'm making a string conversion program in order to make one sentance to be converted into a code. But i'm having some problems and could use some help.
The problem I'm having is that it would replace the letters with the converted one. |
Author: | wtd [ Sat Mar 26, 2005 1:10 pm ] | ||||
Post subject: | |||||
The replace method is not a destructive method. It doesn't change the string it's called on, but rather returns a new string with those changes made. The String doc. Also, there is a difference between:
Abd:
The first is a character, and the second is a string with only one character. Java knows the difference, and cares about it. Your third problem is that you want to do several replaces in a row. So if you change all of the As to Bs, then your next step is to change all of the Bs to Cs, then you've just changed both As and Bs to Cs. You'll need to process the string character by character to avoid this. |