Suppose I have the following in String format:
2.2
And I want to replace the decimal point with an empty space, to make it look like this:
22
How do I do this? I thought replace would have done the trick, but when I try it like this:
string.replace('.', '');
I get an error with the '' because it supposedly isn't a character. That makes sense, so how else can I accomplish what I want?
解决方案
If you just exchange single for double quotes, this will work because an empty string is a legal value. It seems that many people overlook the fact that replace(CharSequence, CharSequence) actually works on string arguments :)