您的位置:首页 > 其它

替换文本中的指定内容(电子邮件),以及其它指定的内容

2010-08-26 14:32 337 查看
<div>
<asp:TextBox ID="TextBox1" runat="server" Width="519px"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Button" Width="65px"
onclick="Button1_Click" /><br />
<asp:TextBox ID="TextBox2" runat="server" Width="520px"></asp:TextBox>
</div>

protected void Button1_Click(object sender, EventArgs e)
{
Regex regex = new Regex(@"([/w-]+(/./w+)*@([/w-]+/.)+/w{2,3})", RegexOptions.IgnoreCase); 正则根据自己的需求进行更改。
string str= regex.Replace(TextBox1 .Text, ""); 将textBox1文本框中的电子邮件替换为"",替换内容可自定义
Match match = regex.Match(TextBox1.Text); //匹配文本框的中电子邮件
TextBox2.Text = match .Groups [0].Value ; //取出文本框中的电子邮件
}

MatchCollection match = regex.Matches(str); //匹配多条
for (int i = 0; i < match.Count; i++)
{
//循环读取match内容
}

//去除HTML标记

public static string StripAllTags(string stringToStrip)
{
stringToStrip = Regex.Replace(stringToStrip, "</p(?://s*)>(?://s*)<p(?://s*)>", "/n/n", RegexOptions.IgnoreCase | RegexOptions.Compiled);
stringToStrip = Regex.Replace(stringToStrip, "<br(?://s*)/>", "/n", RegexOptions.IgnoreCase | RegexOptions.Compiled);
stringToStrip = Regex.Replace(stringToStrip, "/"", "''", RegexOptions.IgnoreCase | RegexOptions.Compiled);
stringToStrip = Regex.Replace(stringToStrip, "<[^>]+>", "", RegexOptions.IgnoreCase | RegexOptions.Compiled);
stringToStrip = Regex.Replace(stringToStrip, "&[^;]+;", "", RegexOptions.IgnoreCase | RegexOptions.Compiled);

return stringToStrip;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: