[thelist] Parsing URLs in ASP.net
Howard Cheng
howcheng at ix.netcom.com
Tue Jun 4 11:58:00 CDT 2002
In ASP.NET you'll be using (assuming you're using VB.NET) something like
the following: (not tested!)
Imports System
Imports System.Text.RegularExpressions
Public Class MyClass
Private httpExpression As String =
"(http|ftp|https):\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?"
Public Function MakeLink(sInput As String) As String
Dim re As New Regex(httpExpression, Regex.IgnoreCase)
Dim oMatch As Match
Dim sOutput As String = ""
If re.IsMatch(sInput) Then
oMatch = re.Match(sInput)
sOutput = "<a href=""" & oMatch.Result & """>" & oMatch.Result &
"</a>"
End If
Return sOutput
End Function
End Class
If you're really daring, you could also try using the UriBuilder class. (:
At 04:39 PM 6/4/2002 +0100, Norman Beresford wrote:
>httpExpression =
>"(http|ftp|https):\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#]
>)?"
>
> Set objRegExpr = New regexp
> objRegExpr.Pattern = httpExpression
> objRegExpr.Global = True
> objRegExpr.IgnoreCase = True
> Set colMatches = objRegExpr.Execute(stringValue)
>
> For Each Item in colMatches
> stringValue = replace(stringValue, Item.Value, "<link
> target=""" &
>Item.Value & """>" & Item.Value & "</link>")
> Next
::::::::::::::::::::::
Howard Cheng
howcheng at ix.netcom.com
AIM: bennyphoebe
ICQ: 47319315
More information about the thelist
mailing list