replace in strings

CitizenX used Ask the Experts™
how can i replace a certain char or space in a string ?
stringname.replace('e','a') replaces e's with a's right ? and how about space ? like cutting out all spaces from a string to make "my name is citizenx" to "mynameiscitizenx" ?
thanks for any help
Greets CitizenX
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

try stringname.replace(' ','');
To chop the spaces out of a String simply use StringTokenizer as follows,

String name = "";

StringTokenizer st = new StringTokenizer("my name is citizenx");

     while (st.hasMoreTokens())
         name += st.nextToken();


you rock my friend, i've been asking lots of people and you were the only one with this idea

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial