using system;
using system.text.regularexpressions;
namespace commlayer
{
/// <summary>
/// 自动给邮件地址或email地址加上url
/// </summary>
public class hyperlinkurl
{
private static regex urlregex = new regex(@"(http:////([/w.]+//?)/s*)",
regexoptions.ignorecase|regexoptions.compiled);
private static regex emailregex = new regex(@"([a-za-z_0-9.-]+/@[a-za-z_0-9.-]+/./w+)",
regexoptions.ignorecase|regexoptions.compiled);
public hyperlinkurl()
{
}
/// <summary>
/// 生成带连接的字符串
/// </summary>
/// <param name="link">需要生成带连接地址的字符串</param>
/// <returns>经过转换的字符串</returns>
public static string genhyperlinkurl(string link)
{
link = emailregex.replace(link, "<a href=mailto:$1>$1</a>");
link = urlregex.replace(link, "<a href=/"$1/" target=/"_blank/">$1</a>");
return link;
}
}
}
,欢迎访问网页设计爱好者web开发。新闻热点
疑难解答