Hello, so I'm working on some code to remove whitespace within String data type variables that hold values such as: " Hello World " and "* Hello World *".
I know for the first option, you could use the .trim() method. So I messed around and added the '*' character at the front and back, now it doesn't trim the inner whitespace. Could I get an explanation as to why this doesn't work and an alternative to how I could trim the inner whitespace?
Much appreciated, thank you.
As for what I've tried so far, I haven't tried anything as of yet as I've just gotten back. I did ponder about it thinking maybe I could combine the .substring() method with .trim(), but as to how to do it. I'm sure. Thanks again.
P.S. - This is all of the code, it can be simply thrown right into main and do what I'm trying to figure out/where I'm at.
String myS = " Hello World! "; System.out.println(myS); System.out.println(myS.trim()); myS = "* Hello World! *"; System.out.println(myS); System.out.println(myS.trim());