您的位置:首页 > 其它

使用正则表达式实现搜索关键字高亮显示

2010-10-13 17:22 337 查看
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication5._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Literal runat="server" ID="lb"></asp:Literal>
<hr />
<asp:Button runat="server" ID="submit"  Text="搜索" onclick="submit_Click"/>
</div>
</form>
</body>
</html>


using System;

using System.Text.RegularExpressions;

namespace WebApplication5
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
lb.Text = "ares@xizhang.com 555 ares@microsoft.com";
}
}

protected void submit_Click(object sender, EventArgs e)
{
string temp = lb.Text;
lb.Text = Regex.Replace(temp, @"[/w/.=-]+@[/w/.-]+/.[/w]{2,3}", c => { return string.Format("<span style="background-color:yellow" mce_style="background-color:yellow">{0}</span>", c); });

}
}
}


/article/4660646.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐