Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey i want to write a script to high lite a particular word in textarea. I know to do it for a particular div,but i don't know to do it for a particular word.
Posted
Comments
ArunRajendra 8-Apr-14 4:42am    
I guess its not possible using TextArea. You have to think of some other alternative.

1 solution

ASP.NET
<asp:textbox rows="10" columns="30" textmode="MultiLine" id="txtSearch" runat="server" text="When implementing some software for another project, I came across several requirements involving calculations with time periods. These calculations were an important part of the solution and had high demands in respect to the correctness and accuracy of the results." xmlns:asp="#unknown"></asp:textbox>
           <asp:label id="lmsg" runat="server" xmlns:asp="#unknown"></asp:label>
           <asp:button id="btnSearch" runat="server" text="Search" onclick="btnSearch_Click" xmlns:asp="#unknown" />



C#
protected void btnSearch_Click(object sender, EventArgs e)
    {
        lmsg.Text = HighlightFont(txtSearch.Text, "implementing");
    }
    protected static string HighlightFont(string Search_Str, string InputTxt)
    {
        if (InputTxt != "" && (Search_Str.ToLower().IndexOf(InputTxt) != -1))
        {
            var dictionary = new Dictionary
            {
               {InputTxt,"" + InputTxt + ""}
            };
            var regex = "(" + String.Join(")|(", dictionary.Keys.ToArray()) + ")";

            foreach (Match metamatch in Regex.Matches(Search_Str, regex, RegexOptions.IgnoreCase))
            {
                Search_Str = Search_Str.Replace(metamatch.Value, dictionary[metamatch.Value.ToLower()]);
            }
            return Search_Str;
        }
        else
        {
            return Search_Str;
        }
    }
 
Share this answer
 

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