html5中文学习网

您的位置: 首页 > 网络编程 > ASP.NET » 正文

C#公共类收集_.NET教程_编程技术

[ ] 已经帮助:人解决问题
1.替换目标字符串中的url 成为超链接

using System;
using System.Text.RegularExpressions;

namespace ArLi.CommonPrj
{
public class ReplaceLink
{
public ReplaceLink()
{
}

/// <summary>替换目标字符串中的url 成为超链接</summary>
/// <param name="myStr">要替换的字符串</param>
public static string rpOf(string myStr) {
myStr += " ";
Regex myre = new Regex(@"http:///S+ ", RegexOptions.IgnoreCase);
MatchCollection mclist = myre.Matches(myStr);
foreach (Match m in mclist){
myStr = myStr.Replace(m.Value,"<a href=/"" + m.Value.Remove(m.Value.Length-1,1) + "/"> ");
}
return myStr.Remove(myStr.Length -1,1);
}
}
}


pHSHTML5中文学习网 - HTML5先行者学习网
pHSHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助