Regular Expressions - Replace

G

Guest

Hi

I want to replace a word using Regular Expression for that i am using below
code

strResult = System.Text.RegularExpressions.Regex.Replace(strInput,
txtSearch.Text.ToString().Trim(), "<b>" + txtSearch.Text.ToString().Trim() +
"</b>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

strInput = "This is a Test."
txtSearch.Text = "test"
strResult ="this is a <b>test</b>."

I want capital 'T' <test> in strResult what should i do?

Thanks in advance
Regards
Hemant
 
H

Hans Kesting

Hemant said:
Hi

I want to replace a word using Regular Expression for that i am using
below code

strResult = System.Text.RegularExpressions.Regex.Replace(strInput,
txtSearch.Text.ToString().Trim(), "<b>" +
txtSearch.Text.ToString().Trim() + "</b>",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);

strInput = "This is a Test."
txtSearch.Text = "test"
strResult ="this is a <b>test</b>."

I want capital 'T' <test> in strResult what should i do?

Thanks in advance
Regards
Hemant

I think you want the overload of the Replace method that uses
a MatchEvaluator as second parameter.

http://msdn.microsoft.com/library/d...tregularexpressionsregexclassreplacetopic.asp

Hans Kesting
 
G

Guest

Thank you Hans for quick reply.

According to your post
This will make starting first characters capital... but i dont want that, I
want to retain the original state of the word. I am using this for site
search using Index server.

For more help,

Suppose user searches for keyword = Test
and suppose we found this keyword in the search result. The contents of the
file is <This is test>.

so if i apply your suggested post the result will be 'This Is Test' which is
wrong.
actaully what i want that It should show the result as
This is <b> test </b>
here the word 'test' should be bold and nothing else should change.

Thank you
Regards
Hemant
 
H

Hans Kesting

Hemant said:
Thank you Hans for quick reply.

According to your post
This will make starting first characters capital... but i dont want
that, I want to retain the original state of the word. I am using
this for site search using Index server.

No, that "first capital" is just an example to show that you have access to
the exact text found. What *you* should do is just take the text found and
 
G

Guest

Thank you Hans

Hans Kesting said:
No, that "first capital" is just an example to show that you have access to
the exact text found. What *you* should do is just take the text found and
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top