469,603 Members | 2,069 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,603 developers. It's quick & easy.

Find and replace problem


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?

Nov 19 '05 #1
2 1299
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" <Ra*********@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...

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?

Nov 19 '05 #2
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

an*********@hotmail.com
"Raed Sawalha" <Ra*********@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...

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?

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

25 posts views Thread by Neo Geshel | last post: by
1 post views Thread by James Vitale | last post: by
13 posts views Thread by Murali | last post: by
14 posts views Thread by inpuarg | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.