The replaceAll statement does work, try the following example.
public final class RemoveSpaces {
public static void main(String[] argv) {
String s = "TEST SPACE A B CCC D";
System.out.println(s + " " + s.replaceAll(" ", "");
}
}
It's a common mistake to forget, that Strings are final in Java.
If you say:
String s = "A great example";
s.replaceAll (" ", "#"
S.o.p (s);
s in still the same.
If you have read the documentation carefully, you would have seen, that s.replaceAll (a,b) RETURNS a String, in which all a are replaced with b.
It doesn't affect s itself.
But if you assign that result to s again:
s = s.replaceAll (a, b);
S.o.p (s);
you will get the intendet result.
'replaceAll statement dont work' is a kind of 'select is broken'-Pattern, see: pragmatic programmer, d.thomas, a.hunt.
>stefanwagner
>the replaceAll statement dont work.
Function replaceAll works and it returns a string what you need. And it is the right function to use in this case. How to use this function is written in a lot of manuals, so I've shown only the right direction.
If someone point you with the finger to the moon and you look at the finger, you will not see the moon.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.