PC Review


Reply
Thread Tools Rate Thread

Regex: replace first occurence only?

 
 
Alexey Smirnov
Guest
Posts: n/a
 
      2nd Apr 2006
Regex.Replace("BUILDING IN PARIS, IN LONDON" ,"\bIN\b","???");
returns "BUILDING ??? PARIS, ??? LONDON"

I need to replace the first match only, to have "BUILDING ??? PARIS, IN
LONDON"

How can I do that?

Thanks.


 
Reply With Quote
 
 
 
 
Cerebrus
Guest
Posts: n/a
 
      3rd Apr 2006
Hi Alexey,

Many of the overloads of the Regex.Replace method allow you to choose a
number to specify the number of occurrences of a match that you would
like to replace. Check them out and choose the one that is most
appropriate for you.

Possibly, you could use this one : Regex.Replace("input",
"replacement", count)...

Regards,

Cerebrus.

 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      12th Apr 2006
thank you, I found how to do that (forgot to check documentation :-)


"Cerebrus" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Alexey,
>
> Many of the overloads of the Regex.Replace method allow you to choose a
> number to specify the number of occurrences of a match that you would
> like to replace. Check them out and choose the one that is most
> appropriate for you.
>
> Possibly, you could use this one : Regex.Replace("input",
> "replacement", count)...
>
> Regards,
>
> Cerebrus.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use regex.replace to replace a group #, not the whole match string justin.mayes@gmail.com Microsoft VB .NET 1 3rd Jun 2006 12:07 AM
Regex: replace first occurence only? Alexey Smirnov Microsoft Dot NET Framework 2 12th Apr 2006 01:13 AM
Cannot replace parenthesis using regex.replace? =?Utf-8?B?U3RlcGhhbmU=?= Microsoft Dot NET 16 13th Oct 2005 08:17 PM
Performance Regex Replace vs StringBuilder Replace Jay B. Harlow [MVP - Outlook] Microsoft VB .NET 8 22nd Mar 2004 02:08 AM
Replace methode, Replace Function, Stringbuilder replace, Regex Replace, Split Cor Microsoft VB .NET 4 1st Mar 2004 03:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:35 AM.