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

 用正则表达式来完成

  Function DeLink(ByVal htmlText As StringAs 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 StringAs 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, "[url=" & m.Groups(1).Value & "]" & m.Groups(2).Value & "[/url]")
        
Next
        
Return htmlText
    
End Function


类似这样做其它的标签就可以完在基本的UBB功能
呵呵,太懒了,写字日少
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值