On 8/24/05, Daniel Michaeloff <[EMAIL PROTECTED]> wrote:
> Hi all,
> 
> I want to replace '%' with an expression in a string, except for escaped
> '%%' which should go to '%'.
> 
> For example, replacing "%" with "PCNT":
> 
> "a%b%%c%%%d%%%%e%%%%%f"
> 
> should result in
> 
> "aPCNTb%c%PCNTd%%e%%PCNTf"
> 
> Is there a way to do this in one shot with Regex.Replace()?

You need to replace two different strings, so the simple overloads won't do it.

In DotLisp [Tested]:

(Regex:Replace "a%b%%c%%%d%%%%e%%%%%f"
  "%%|%" (make-delegate MatchEvaluator. (m)
    (if (== m.Value "%%")
      "%"
      "PCNT")))

VB.NET [Air code]:

Function PTest(ByVal m As Match) As String
If m.Value = "%%" Then
  Return "%"
Else
  Return "PCNT"
End If
End Function
...
  Console:WriteLine(Regex.Replace("a%b%%c%%%d%%%%e%%%%%f", _
    "%%|%", AddressOf(PTest)))
...
Regards,
Mark Hurd, B.Sc.(Ma.)(Hons.)

P.S. Gmail headers cause you to reply to me instead of the list -- be warned!

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to