Click here to Skip to main content
15,920,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi this is my code

MResult = MResult.Replace(txtSearch.Text, "<span style=\"color:#c1330e; padding:0px 2px 0px 2px\">" + txtSearch.Text + "</span>");


here i give txtSearch.Text.tolower() it takes only lowecase oly.
here from literal text am selecting my textbox text alone

if i give lowecase or uppercase it want to show correctly. how can it work for all case?
Posted
Updated 19-Jul-11 19:49pm
v2

Try as below.
string MResult = "hdshdjshdjsinputhdjshdjhdINPUTDHSJHDJInputdhsdjshdjhdj";
string search = txtSearch.Text;//"input"
string replaceWith = "1234";
MResult = System.Text.RegularExpressions.Regex.Replace(MResult, search, replaceWith, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
 
Share this answer
 
v2
Comments
suryaswathi 20-Jul-11 2:31am    
its not working
RaisKazi 20-Jul-11 2:35am    
Can you share your code? It should work, I have tested it for all cases.
suryaswathi 20-Jul-11 2:37am    
MResult = MResult.Replace(txtSearch.Text, "<span style=\"color:#c1330e; padding:0px 2px 0px 2px\">" + txtSearch.Text + "</span>");

MResult = MResult.Replace(txtSearch.Text.ToLower(), "<span style=\"color:#c1330e; padding:0px 2px 0px 2px\">" + txtSearch.Text + "</span>");
MResult = MResult.Replace(txtSearch.Text.ToUpper(), "<span style=\"color:#c1330e; padding:0px 2px 0px 2px\">" + txtSearch.Text + "</span>");
//MResult = MResult.Replace(txtSearch.Text, "<span style=\"color:#c1330e; padding:0px 2px 0px 2px\">" + txtSearch.Text + "</span>");

string MResult1 = MResult = MResult.Replace(txtSearch.Text, "<span style=\"color:#c1330e; padding:0px 2px 0px 2px\">" + txtSearch.Text + "</span>");
string search = txtSearch.Text;//"input"
string replaceWith = txtSearch.Text;

MResult = System.Text.RegularExpressions.Regex.Replace(MResult1, search, replaceWith, System.Text.RegularExpressions.RegexOptions.IgnoreCase);

ltrlDataString.Text += MResult;
RaisKazi 20-Jul-11 2:42am    
Don't use "MResult.Replace" because it should work using "System.Text.RegularExpressions.Regex.Replace".

Go back to my given code. Only you have to change it as below.

string replaceWith = "<span style=\"color:#c1330e; padding:0px 2px 0px 2px\">" + txtSearch.Text + "</span>";
suryaswathi 20-Jul-11 2:58am    
hi thanks..its working..thanku very much.
A textbox will store text in the format (i.e. upper or lower case) you enter - so you should not be facing any problems in this.
Just the default text box should work correctly.
 
Share this answer
 
Comments
suryaswathi 20-Jul-11 2:08am    
if i give hurry mean in myresult hurry oly selected .i want to select Hurry also.dis is my pblm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900