VB.net replace whole string  matches in another string

Murray Brown
Murray Brown used Ask the Experts™
on
Hi

I have a  long string that I need to find and replace other substrings in. There could be multiple occurrences of each substring What code do I use?

For example:
If my main string is "I eat a lot of chicken (but I prefer steak to chicken)"
How do I replace the words "chicken" with "poultry" and "steak" with "beef" ?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Kent DyerIT Security Analyst Senior

Commented:
Simple..
Replace(yourtext,"chicken","poultry")

Open in new window

Or..
Replace(yourtext,"steak","beef")

Open in new window


HTH,

Kent
Project manager
Commented:
Or you can use the .NET-way :)

Dim myString as string = ""I eat a lot of chicken (but I prefer steak to chicken)"
myString = myString.Replace("chicken","poultry")

See also http://www.dotnetperls.com/replace-vbnet
Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
Thanks very much

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial