This content has been marked as final. Show 7 replies
Yea sure, sorry if I didn't explain it very well.
Say I have a string "Hello"
I want to change each character of this string to a unique character (determined by an algorithm in my program) so an example of the updated string could be:
But, as I understand it using the replace function, would replace 'l' in 'Hello' with the same character.
Hope that's a bit clearer
I guess you want to replace multiple characters at the same time. If I am correct, you have to write such a method yourself. It's easy using a StringBuilder (or StringBuffer in JDK1.4-), an index variable and some character mappings.
Note that you cannot manipulate a String, as it is immutable. You will always have to create a new String having the new or copied content.
Sorry I specified my example slightly wrong. The replacement char doesn't have to be unique, but most likely will be. I was just trying to make the example that two same letters in the first string will (most likely) be changed to different values.
Thanks for the all the replies :)
I'm going to check out StringBuilder first, as it looks like that would work