473,395 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 1413
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
1
by: James Vitale | last post by:
Using vb asp.net 1.1 I'm doing a word automation on a doc file and trying to do a find and replace. My existing code works fine except that it doesn't find and replace in the header. My code...
13
by: Murali | last post by:
Given: L = list of integers. X and Y are integers. Problem: find every occurence of X and replace with Y Solution1: def check(s): if s==X: return Y else return s newL =
0
by: Xah Lee | last post by:
Interactive Find and Replace String Patterns on Multiple Files Xah Lee, 2006-06 Suppose you need to do find and replace of a string pattern, for all files in a directory. However, you do not...
14
by: inpuarg | last post by:
I want to find a & character using Regex. But not && How can i manage this in c# Quickfind window ? -------------------------------------------------- ne kadar yaşarsan yaşa sevdiğin kadardır...
8
by: John Pye | last post by:
Hi all I have a file with a bunch of perl regular expressions like so: /(^|)\*(.*?)\*(|$)/$1'''$2'''$3/ # bold /(^|)\_\_(.*?)\_\_(|$)/$1''<b>$2<\/ b>''$3/ # italic bold...
9
by: JoeP | last post by:
Hi All, How can I find the reason for such an error: Failure sending mail. Some Code... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient...
2
by: santhescript01 | last post by:
Hi everyone, I got a macro that performs a find and replace function on a text.It's working fine but for some unicode character it replaces with weird character despite of original text character. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.