您的位置:首页 > 编程语言

.net实现自定义UBB代码及规则的基本实现

2007-03-29 22:17 323 查看
用正则表达式来完成

Function DeLink(ByVal htmlText As String) As String '进行A标签解码
Dim hrefRegex As New Regex( _
"[urls*=s*([^""]+)s*]([sS]*?)[/url]", _
RegexOptions.IgnoreCase)
Dim output As String = ""
For Each m As Match In hrefRegex.Matches(htmlText)
htmlText = Replace(htmlText, m.Groups(0).Value, "<a href=""" & m.Groups(1).Value & """>" & m.Groups(2).Value & "</a>")
Next
Return htmlText
End Function

Function EnLink(ByVal htmlText As String) As String '进行A标签编码
Dim hrefRegex As New Regex( _
"<A[^>]*?HREFs*=s*""([^""]+)""[^>]*?>([sS]*?)</A>", _
RegexOptions.IgnoreCase)
Dim output As String = ""
For Each m As Match In hrefRegex.Matches(htmlText)
htmlText = Replace(htmlText, m.Groups(0).Value, "" & m.Groups(2).Value & "")
Next
Return htmlText
End Function

类似这样做其它的标签就可以完在基本的UBB功能
呵呵,太懒了,写字日少
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: