Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Find and replace problem

Reply
Thread Tools

Find and replace problem

 
 
=?Utf-8?B?UmFlZCBTYXdhbGhh?=
Guest
Posts: n/a
 
      08-15-2005

I have the following text:-

Brian went to stadium to watch the soccer game, Brian MacWoods is bussiness
man and very rich man.
Brian likes to run every morning on beachside.

the problem i have I get the list of words that should be replace in the
provided text as follows:-

Brian (ONLY) : should be replaced by Mr with Brian word itself==> will be
after replacing(Mr Brian)
Brian MacWoods (Togather): should be replace by Sr with Brian MacWoods = >
will be after replacing(Sr Brian MacWoods)

how can i achieve this stuff of text replacing without have problem in the
name conflict (that when replay Brian(ONLY) do not replace the Brian in Brian
MacWoods?



 
Reply With Quote
 
 
 
 
Grant Merwitz
Guest
Posts: n/a
 
      08-15-2005
This is a work around

First replace Brian with Mr Brian
MyString.Replace("Brian", "Mr Brian");

Then replace Mr Brian MacWoods (notice the "Mr" is now included) with Sir
Brian McWoods
MyString.Replace("Mr Brian MacWoods", "Sir Brian MacWoods");

HTH

"Raed Sawalha" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> I have the following text:-
>
> Brian went to stadium to watch the soccer game, Brian MacWoods is
> bussiness
> man and very rich man.
> Brian likes to run every morning on beachside.
>
> the problem i have I get the list of words that should be replace in the
> provided text as follows:-
>
> Brian (ONLY) : should be replaced by Mr with Brian word itself==> will be
> after replacing(Mr Brian)
> Brian MacWoods (Togather): should be replace by Sr with Brian MacWoods = >
> will be after replacing(Sr Brian MacWoods)
>
> how can i achieve this stuff of text replacing without have problem in the
> name conflict (that when replay Brian(ONLY) do not replace the Brian in
> Brian
> MacWoods?
>
>
>



 
Reply With Quote
 
 
 
 
Ankit Gurjar
Guest
Posts: n/a
 
      08-15-2005
Hello Raed,

Here you have to make two searches for separate words Brian and
Brian MacWoods. First Search for Word Brian, if you find the match then
search for Brian MacWoods using SubString(strString, intstartPosition,
intStartPosition + Len("Brian MacWoods").

Now of you find the second match then replace for Brian MacWoods
else Replace for Brian only. So here you are searching for Brian first and
immediately searching for Macwoods in next 9 Characters.

I hope this will sort out your problem.


--
Ankit Gurjar

http://www.velocityreviews.com/forums/(E-Mail Removed)
"Raed Sawalha" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> I have the following text:-
>
> Brian went to stadium to watch the soccer game, Brian MacWoods is
> bussiness
> man and very rich man.
> Brian likes to run every morning on beachside.
>
> the problem i have I get the list of words that should be replace in the
> provided text as follows:-
>
> Brian (ONLY) : should be replaced by Mr with Brian word itself==> will be
> after replacing(Mr Brian)
> Brian MacWoods (Togather): should be replace by Sr with Brian MacWoods = >
> will be after replacing(Sr Brian MacWoods)
>
> how can i achieve this stuff of text replacing without have problem in the
> name conflict (that when replay Brian(ONLY) do not replace the Brian in
> Brian
> MacWoods?
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 3 02-14-2011 05:28 AM
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 0 02-10-2011 05:18 PM
Re: [Pyrex] pyrex functions to replace a method (Re: replace a method Greg Ewing Python 2 06-29-2006 05:25 PM
pyrex functions to replace a method (Re: replace a method in class:how?) Brian Blais Python 1 06-27-2006 12:13 PM
Find.find does not find orphaned links? Wybo Dekker Ruby 1 11-15-2005 02:50 PM



Advertisments