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);
}
}
}
博客介绍了如何替换目标字符串中的URL成为超链接。通过使用System和System.Text.RegularExpressions命名空间,定义了ReplaceLink类,其中的rpOf方法利用正则表达式匹配URL,并将其替换为超链接格式,最后返回处理后的字符串。
2882





