468,484 Members | 1,622 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Case-Insensitive Replace


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!!
Nov 20 '05 #1
1 3526
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.

Similar topics

17 posts views Thread by Newbie | last post: by
19 posts views Thread by Robert Scheer | last post: by
1 post views Thread by ST | last post: by
6 posts views Thread by deanfamily11 | last post: by
15 posts views Thread by YitzHandel | last post: by
7 posts views Thread by Lauren Quantrell | last post: by
22 posts views Thread by John | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.