I take it the String.replace(char, char) method not not change the string permanently? I mean, if I run the below program, what prints out on the command line is the muted string, but what appears in the JOptionPane after the replace() command is used is the original string, not modified. How can I change the string? Only by assigning it a new value completely?
Hello. My name is Inigo Montoya. You killed my father. Prepare to die.
Not only does it not change the string permanently, it doesn't change the string at all. The documentation is quite clear about this, it says about that method
Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
In fact there are no methods that change a string in any way.
You can of course assign a new string to a variable, which I think is what you want to do. But that doesn't constitute changing a string, it only assigns a different string to the variable and leaves the original string unchanged. [ April 11, 2007: Message edited by: Paul Clapham ]
Joined: Aug 17, 2006
Thanks, Paul, if it returns a string I know how to use it. So, strings really are immutable, after all...
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: String.replace(char, char) method - not changing string permanently