Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
|
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 24th, 2003, 11:18 AM
Registered User
 
Join Date: Sep 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Replace space with nothing.

I need som help how to replace " " (space) with "" (nothing) (no quotas). Is there any one how know how to do this?
E.g.
Iam a nice boy! = Iamaniceboy!

- eXon
 
Old September 24th, 2003, 09:24 PM
Registered User
 
Join Date: Jun 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

String myString = "123 456";
System.out.println("Output: " + myString.replace(" ", ""));


Thanks

Neo Gigs
 
Old September 26th, 2003, 03:16 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The method myString.replace(' ', '') servers to replace a character on the other hand.
For witch you request uses:
     numero.replaceAll(" ", "");
 
Old October 24th, 2003, 02:10 AM
Registered User
 
Join Date: Oct 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
check whether the following code helps you...
rgrds

String s = new String("abc def");
  char[] ca = s.toCharArray();
  int iStrLen = s.length();
  char[] CResultArr = new char[iStrLen + 1];
  int j = 0;
  for ( int i=0; i< iStrLen; i++ ) {
     switch ( ca[i] ) {
     case ' ':
        break;
     default:
       CResultArr[j] = ca[i];
       j++;
        break;
     } // end switch
  } // end for
   s = new String (CResultArr);
  System.out.println(s);






Similar Threads
Thread Thread Starter Forum Replies Last Post
Looks like a space but it isn't. rstelma SQL Server 2000 3 September 7th, 2005 07:17 PM
replace a ' (apostrophe) with a space crmpicco Javascript How-To 3 April 28th, 2005 06:53 AM
space crmpicco Javascript How-To 1 February 7th, 2005 01:26 PM
plus '+' replace by space " " in binary stream rupakb XML 0 October 26th, 2004 11:35 AM
how to replace space with ; mp218 Access VBA 4 August 5th, 2003 07:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.