Removing Spaces in Strings | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

2nd Jun 2018, 5:43 PM
Andre Daniel
Andre Daniel - avatar
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
2nd Jun 2018, 6:02 PM
ifl
ifl - avatar
0
It works for me (as, your code gives the result I expect) what makes you think it is wrong?
2nd Jun 2018, 5:59 PM
ifl
ifl - avatar
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?
2nd Jun 2018, 6:01 PM
Andre Daniel
Andre Daniel - avatar