using system;
using system.text.regularexpressions;
namespace commlayer
{
/// <summary>
/// 自動(dòng)給郵件地址或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>經(jīng)過轉(zhuǎn)換的字符串</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;
}
}
}
,歡迎訪問網(wǎng)頁(yè)設(shè)計(jì)愛好者web開發(fā)。新聞熱點(diǎn)
疑難解答
圖片精選