你这个功能实现起来应该说比较简单,但问题是你的源字符串是什么形式的,我该如何从源字符串中判断,哪一个或多个字符串是我要转换的也就是,我该如何从你的源字符串中识别
www.abc.com、http://www.abc.com、abc.com
这三种形式

解决方案 »

  1.   

    string strContent = InputTextBox.Text;
    Regex urlregex = new Regex(@"(http:\/\/([\w.]+\/?)\S*)",
    RegexOptions.IgnoreCase| RegexOptions.Compiled);
    strContent = urlregex.Replace(strContent,
    "<a href="" target="_blank"></a>");
    Regex emailregex = new Regex(@"([a-zA-Z_0-9.-]+@[a-zA-Z_0-9.-]+\.\w+)",
    RegexOptions.IgnoreCase| RegexOptions.Compiled);
    strContent = emailregex.Replace(strContent, "<a href=mailto:></a>");
    lbContent.Text += "<br>"+strContent;这个好象不行,大家帮我看看
      

  2.   

    随便写了一个,只是处理了.com的情况,楼主不回我问题,我也没辙string yourStr = ...........;
    string resultStr = Regex.Replace(yourStr, @"(http://)?(www.)?([\w-]+\.com)", new MatchEvaluator(regReplace), RegexOptions.IgnoreCase);
    private string regReplace(Match m)
    {
        if(m.Value.StartsWith("http://"))
        {
            return "<a href='"+m.Value+"'>"+m.Value.Remove(0,7)+"</a>";
        }
        else if(m.Value.StartsWith("www"))
        {
            return "<a href='http://"+m.Value+"'>"+m.Value+"</a>";
        }
        else
        {
            return "<a href='http://www."+m.Value+"'>www."+m.Value+"</a>";
        }
    }