Find and replace problem

G

Guest

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?
 
G

Grant Merwitz

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
 
A

Ankit Gurjar

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top