Home arrow static arrow Java Programming [Archive] - replacing whitespace
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - replacing whitespace
This topic has 1 reply on 1 page.

Posts:6
Registered: 7/13/04
replacing whitespace  
Jul 15, 2004 6:37 AM



 
Hi,

Can anybody advise me on how to replace the whitespace in a string for another char.

Say I have a string String eg = "TESTING=TEST NOT TEST*"

I want to replace all the white space with a + charcater so the string would look like

"TESTING=TEST+NOT+++++++++TEST*"

I tried the replacre method but that did not work.

eg.replace(' ', '+');

Thanks for the help guys!
 

Posts:3,055
Registered: 18/06/98
Re: replacing whitespace  
Jul 15, 2004 6:41 AM (reply 1 of 1)



 
Strings are "immutable" objects. The following test code works.

import java.io.*; public class Test33 {	public static void main(String[] args) throws Exception {	    String eg = "TESTING=TEST NOT         TEST*";	    eg = eg.replace (' ', '+');	    System.out.println (eg);    }}
 
This topic has 1 reply on 1 page.