THANK YOU!
> Regex.Replace(string.format("({0})", Regex.Escape(input)), "<b>$1</b>", RegexOptions.IgnoreCase)
Presuming
user search input : textboxSearch.text
replace is : "<b>"+textboxSearch.text+"</b>"
data I'm looking to impact is : Research.Text (a gridview row label
control)
How would I use the above?
I tried:
Imports System.Text.RegularExpressions
Research.Text = Regex.Replace(String.Format("({0})",
Regex.Escape(textboxSearch.Text)), "<b>$1</b>",
RegexOptions.IgnoreCase)
Getting an error on Regex.Replace : Reference to a non-shared member
requires an object reference.
So I noticed it appears to be formated incorrectly and probably should
be :
Research.Text = Regex.Replace(String.Format("({0})"),
Regex.Escape(textboxSearch.Text), "<b>$1</b>",
RegexOptions.IgnoreCase)
However that did not work.
I also tried:
No effect:
Research.Text = Regex.Replace(String.Format("({0})"),
Regex.Escape(textboxSearch.Text), "<b>$1</b>",
RegexOptions.IgnoreCase)
replaces string with actually "$1":
'Research.Text = Regex.Replace(Research.Text,
Regex.Escape(textboxSearch.Text), "<b>$1</b>",
RegexOptions.IgnoreCase)
works, in finding the strings, but replaces with wrong case:
'Research.Text = Regex.Replace(Research.Text,
Regex.Escape(textboxSearch.Text), "<b>"+ textboxSearch.Text+"</b>",
RegexOptions.IgnoreCase)
Thanks again.
Jesse Houwing - 07 Mar 2008 14:36 GMT
Hello wildman@noclient.net,
> THANK YOU!
>
>> Regex.Replace(string.format("({0})", Regex.Escape(input)),
>> "<b>$1</b>", RegexOptions.IgnoreCase)
> Presuming
>
[quoted text clipped - 38 lines]
> Regex.Escape(textboxSearch.Text), "<b>"+ textboxSearch.Text+"</b>",
> RegexOptions.IgnoreCase)
Sorry, I mixed the input and the pattern parameters to the Regex.Replace
function.
This should do it (in C#, I'm no star in VB):
string input = "a.b.c.d.e.f.g.h.i.j";
string output = Regex.Replace(input, string.Format("({0})", Regex.Escape(input)),
"<b>$1</b>");
Console.WriteLine(output);
--
Jesse Houwing
jesse.houwing at sogeti.nl
wildman@noclient.net - 12 Mar 2008 21:05 GMT
I'm close, but this ends up highighting all of research.text when a
match is found. How can I highlight just the found string in it's
original case?
Research.Text = Regex.Replace(Research.Text, String.Format("({0})",
Regex.Escape(Research.Text)), "<FONT style='background-color:Yellow'>
$1</FONT>")
thanks.
Jesse Houwing - 14 Mar 2008 19:38 GMT
Hello wildman@noclient.net,
> I'm close, but this ends up highighting all of research.text when a
> match is found. How can I highlight just the found string in it's
[quoted text clipped - 3 lines]
> Regex.Escape(Research.Text)), "<FONT style='background-color:Yellow'>
> $1</FONT>")
That shouldn't be too hard, but currently you're puttign the whole string
in for both input and pattern.
> Research.Text = Regex.Replace(
Research.Text, <== input
String.Format("({0})", Regex.Escape(Research.Text)), <== text to search
"<FONT style='background-color:Yellow'>$1</FONT>" <== replacement
)
So make sure you only put the text to search in the correct place.
--
Jesse Houwing
jesse.houwing at sogeti.nl