By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,258 Members | 1,602 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,258 IT Pros & Developers. It's quick & easy.

Case-Insensitive Replace

P: n/a
Howdy,

I'm making a search engine for an application I'm working on. I want to "bold" keywords they have searched for. I have a long string of words that represents a particular document, and I need to find out how to do a replace on this string, but have it be case-insensitive.
For instance:

dim docWords as string = "BLAH blah BlaH!"
dim myString as string = "blah"
docWords = docWords.Replace(myString, "<b>" & myString & "</b>")

My end result would be:
"<b>BLAH</b> <b>blah</b> <b>BlaH</b>!"

Right now, naturally, I only get this
"BLAH <b>blah</b> BlaH!"

I think may have to use Regex.Replace somehow, but I'm unsure how to proceed with that in order to make the search expression case insensitive. I really don't want to mess with the myString parameter too much as these words can be ever changing

I've tried using .tolower functions, which works great, but when it comes to displaying the result, everything is lowercase.

Any help would be great!!
--Michael
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
gb
Try this

dim docWords as string = "BLAH blah BlaH!
dim myString as string = "blah
docWords = Replace(docWords, myString, "<b>" & myString & "</b>", 1, ,CompareMethod.Text

Hope this help
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.