tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Einfeldt <ralph.einfe...@uptime-isc.de>
Subject AW: Replacing ALL Whitespace in string
Date Wed, 20 Dec 2000 08:48:30 GMT

replace() inj class String is intended to to replace 
a character with another.
If you want to replace spaces with an empty string 
you have to write your own function like this:

public String removeBlanks(String aString) {
  StringBuffer mResult = new StringBuffer();
  StringTokenizer mTokenizer = new StringTokenizer(aString, " ");
  while (mTokenizer.hasMoreElements()) {
    mResult.append(mTokenizer.nextToken());
  }
  return mResult.toString();
}

P.S.: This is a java question, not a tomcat question.

> -----Urspr√ľngliche Nachricht-----
> Von: Mark Franz [mailto:mfranz@praja.com]
> Gesendet: Dienstag, 19. Dezember 2000 22:06
> An: 'tomcat-user@jakarta.apache.org'
> Betreff: Replacing ALL Whitespace in string
> 
> 
> I am trying to replace ALL the Whitespace in a string.  If I do this;
>  
> String newcat = newcat1.replace(' ','');
>  
> I get this error;
>  
> 100. String newcat = newcat1.replace(' ','');
>                                                     <>
> *** Lexical Error: Empty character constant
> 
>  
> My newcat string might look like this;
>  
> ROOT/cat Tree/The Next/Path To/Victory Garden
>  
> 
> Mark G. Franz 
> 
>  
> 

Mime
View raw message