Are you sure? There's not a javadoc I can see that says "abaa" would
become "abaa", in fact it suggests it would be "baa" unless you passed
null as the replace value instead of "".

Are you finding that it's not working this way?

You can also ditch the ,1 and use replaceOnce.

Hen


On Wed, 16 Mar 2005 12:30:36 -0500, Scovetta, Michael V
<[EMAIL PROTECTED]> wrote:
> Hi!
>    I'm looking for a clean way of replacing all instances of a substring
> with another. Sounds easy, right? Here's my desired functionality:
> 
>         MyReplaceAll("abc", "a", "z")    - zbc
>         MyReplaceAll("abc", "a", "")     - bc
>         MyReplaceAll("$1$2$3", "$", "b") - b1b2b3
>         MyReplaceAll("abc", null, "foo") - abc
>         MyReplaceAll("abc", "foo", null) - abc
> 
> String.replaceAll interprets the replacement values as regular
> expressions, and chokes on $-signs. StringUtils.replace is **almost**
> what I'm looking for, but (as per the javadocs):
> 
>         StringUtils.replace("abaa", "a", "", 1)    = "abaa"
> 
> I would expect replacing the String "a" with a blank string would result
> in:
> 
>         StringUtils.replace("abaa", "a", "", 1)    = "baa" (max of one
> replacement specified)
> 
> Am I just missing something here? Is there another function I should use
> to "de-regex" my input strings, or have you guys found a better way of
> doing this?
> 
> Thanks for your help in advance!
> 
> Michael Scovetta
> Computer Associates
> Senior Application Developer
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to