+ 1
Removing Spaces in Strings
I am trying to get "HelloWorld!" when I first type "Hello World!", but running this program simply returns the same "Hello World!" for me. I know using replace(" ", "") works. But why doesn't string.trim() work? It used to (on pc). https://code.sololearn.com/cAzk2rqIytP2/?ref=app
3 Answers
+ 2
Andre Daniel Ah, that's because trim is not supposed to remove spaces in the middle, only start and end.
Google java+trim+whitespace
0
It works for me (as, your code gives the result I expect)
what makes you think it is wrong?
0
ifl unfortunately, when I enter "Hello World", I get back "Hello World" instead of the intended "HelloWorld". How does it work for you and not me?