[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Replace function



Hi all,
	Remember Strings are immutable (the cannot be minipulated directly).
I would suggest using a StringBuffer for you String manipulation needs.

Nicholas Frank

-----Original Message-----
From: Frank Merenda [mailto:fmerenda@atwork.com]
Sent: Friday, October 05, 2001 11:02 AM
To: monel.a.amin@mail.sprint.com; ajug-members@www.ajug.org
Subject: RE: Replace function



Hello!

If you want to replace ALL occurrences of the character, you can use the
following method in the String class:

public String replace(char oldChar, char newChar)

If you want to replace a single character you will have to use the
indexOf() function in the string class to find where the first
occurrence of the character is, then replace it by chopping up the
string into substrings (see substring() method in String class)

Hope that helps!

Thanks,
Frank Merenda
Senior Software Engineer
AtWork Technologies, Inc.
fmerenda@atwork.com 

> -----Original Message-----
> From: monel.a.amin@mail.sprint.com 
> [mailto:monel.a.amin@mail.sprint.com]
> Sent: Friday, October 05, 2001 10:58 AM
> To: ajug-members@www.ajug.org
> Subject: Replace function
> 
> 
> Hi All,
> 
> Is there an VB's Replace function's equivalent in Java?  I need to
> replace a character in a String.
> 
> 
> Any suggestions.....
> 
> Thanks,
> Monel.
> 
>