在textarea中高字节特定单词 [英] To high lite a particular word in textarea

查看:86
本文介绍了在textarea中高字节特定单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我想在textarea中为高字节写一个特定单词的脚本。我知道要为一个特定的div做这个,但我不知道为一个特定的单词做这个。

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.

推荐答案

<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" />

< br $> b $ b






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;
        }
    }


这篇关于在textarea中高字节特定单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆