Response.write("<a href='http://www.abc.com'>http://www.abc.com</a>")

解决方案 »

  1.   

    就是有下面一段string:here is something link to a site,please tell me how to make it useful as when i surfing,the address is http://www.abc.com以上是做为文本显示在html的,我想看的时候,mouse在"http://www.abc.com"的时候变成手掌,一按就可以去www.abc.com.是用programming自动把"http://www.abc.com"变成<a href='http://www.abc.com'>http://www.abc.com</a>,不是手工添加的.请问怎么办?
      

  2.   

    就是用programming把"http://www.abc.com"找出来,把它变成<a href='http://www.abc.com'>http://www.abc.com</a>.
      

  3.   

    首先是你这段文本你是怎么来的,比如是从数据库中来的还是一个Lable,如果是一个Lable,你可以这样:
        Lable1="<a href='http://www.abc.com'>"+Lable1+"</a>"
      

  4.   

    不是啊,其实就是怎样把一段文本,其中"http"带头的字段都变成超文本连接,各位大侠明白我的意思了吗?
      

  5.   

    例:string myStr = "xxxx http://www.myurl.com xxxx http://www.myurl.com/mypage.htm xxx http://myurl/mydir";可用: 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) + "\">");
    }MessageBox.Show(myStr);注意要在前面加个 using System.Text.RegularExpressions;
      

  6.   

    //注意加个 using System.Text.RegularExpressions;/// <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;
    }使用方法:string myText = "xxxx http://www.myurl.com xxxx http://www.myurl.com/mypage.htm xxx http://myurl/mydir";myText = rpOf(myText);Messagebox.Show(myText);
      

  7.   

    上面的仓促之作,有个bug 会少了超链后一个空格
    修正如下:/// <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);
    }
      

  8.   

    终于明白你的问题,在文本中有http:....的字段变成链接是吧?可以用正则表达式或字符串替换(如ArLi2003(阿利 do{失业+失恋}所写的)来做
      

  9.   

    ArLi2003(阿利 do{失业+失恋}:我按照你做的写成以下,但它却把http://www.163.com截掉了,变成了"please"是超文本连接,我想这些http字段也是完整显示在页面上的,请问怎样修改?我是要页面完整显示这段话:go to http://www.163.com please<%@ Page %>
    <%@ Import Namespace="System.IO" %>
    <%@ Import Namespace="System.Web.UI.HtmlControls" %>
    <%@ Import Namespace="System.Text.RegularExpressions" %>
    <HTML>
      <HEAD>
    <script language="C#" runat="server">protected void Page_Load(Object sender, EventArgs e)
        {string myText = "go to http://www.163.com please";
    myText = rpOf(myText);
    Response.Write(myText);} 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);
    } </script>
    </HEAD>
    <body>
    <form runat="server"> </form>
    </body>
    </HTML>
      

  10.   

    Please read this article:http://www.4guysfromrolla.com/webtech/tips/t110900-1.shtml--------------------------------
    AspNetPager 免费分页控件4.0版发布,欢迎下载使用:http://www.webdiyer.com
      

  11.   

    nne998(上上下下左右左右BABA┏^0*0^┑) :可以具体点吗?webdiyer(陕北吴旗娃):我把它做成以下,由于我对VB不熟悉,请问怎样把aa.Value的值通过InsertHyperlinks(inText)转换后,把值给bb.Value?
    <HTML>
      <HEAD>
    <script language="VB" >Function InsertHyperlinks1()InsertHyperlinks(aa.Value)
    End FunctionFunction InsertHyperlinks(inText)
    Dim objRegExp, strBuf
    Dim objMatches, objMatch
    Dim Value, ReplaceValue, iStart, iEnd  strBuf = ""
      iStart = 1
      iEnd = 1
      Set objRegExp = New RegExp  objRegExp.Pattern = "\b(www|http|\S+@)\S+\b"  ' Match URLs and emails
      objRegExp.IgnoreCase = True                   ' Set case insensitivity.
      objRegExp.Global = True                       ' Set global applicability.
      Set objMatches = objRegExp.Execute(inText)
      For Each objMatch in objMatches
        iEnd = objMatch.FirstIndex
        strBuf = strBuf & Mid(inText, iStart, iEnd-iStart+1)
        If InStr(1, objMatch.Value, "@") Then
          strBuf = strBuf & GetHref(objMatch.Value, "EMAIL", "_BLANK")
        Else
          strBuf = strBuf & GetHref(objMatch.Value, "WEB", "_BLANK")
        End If
        iStart = iEnd+objMatch.Length+1
      Next
      strBuf = strBuf & Mid(inText, iStart)
      InsertHyperlinks = strBuf
    'bb.Value=InsertHyperlinks
    End Function
    Function GetHref(url, urlType, Target)
    Dim strBuf  strBuf = "<a href="""
      If UCase(urlType) = "WEB" Then
        If LCase(Left(url, 3)) = "www" Then
          strBuf = "<a href=""http://" & url & """ Target=""" & _
                   Target & """>" & url & "</a>"
        Else
          strBuf = "<a href=""" & url & """ Target=""" & _
                   Target & """>" & url & "</a>"
        End If
      ElseIf UCase(urlType) = "EMAIL" Then
        strBuf = "<a href=""mailto:" & url & """ Target=""" & _
                 Target & """>" & url & "</a>"
      End If
      
      GetHref = strBufEnd Function </script>
    </HEAD>
    <body bgcolor="ffffff" style="margin:0,0,0,0" onload=InsertHyperlinks1()>
    <input id="aa" name="Name1"  value="dfdas http://locd dds" >

    <input id="bb" name="Name2"  value="" >
    </body></HTML>
      

  12.   

    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) + "\"> "+m.Value.Remove(m.Value.Length-1,1)+"</a>");
    }
    return myStr.Remove(myStr.Length -1,1);
    }
      

  13.   

    把 ArLi2003(阿利 do{失业+失恋}) 的代码改了一下