complete noob, direction needed pls.
good day.
i'm busy downloading the java sdk to start my journey down the path of becoming a java bean.
i've got an simple app thati want to try building (i know i havea large learning curve to get over)...
i want to create an app that would take an input string and convert each character to a different character, eg. abcd would become bcde. But i know that using a search and replace function as:
replace a with b, b with c, d with e means that my program will give me a string if i where to build the step line by line
1: bbcd
2: cccd
3: dddd
4: eeee
how would you do a selective search and replace or translating or encoding (i dont know what to lable it)... without encountering the above
thank you in advanced ( and for not critizing my lack of knowledge yet)
Re: complete noob, direction needed pls.
Use different methods and/or classes that allow you to work on the characters one at a time from left to right instead of working on all of the characters each time.
Look at the String class's methods
or the StringBuffer or StringBuilder classes that have methods to access and change individual characters.
Re: complete noob, direction needed pls.
A simple solution is to make all the changes at the same time.
Create a remap method which takes in the input character and what the appropriate output character should be.
Then create a StringBuilder object. This is essentially a mutable String. Then for every character in the old String set the result in the new StringBuilder to the remapped character.
Finally, to convert the StringBuilder object to a String, call the toString method.
Re: complete noob, direction needed pls.
Who said you had to make the changes to the original string? Copy it, then reference back to the original as you make the changes, finally return the copy when it's all done :D