Lotusscript代理调用正则表达式过滤掉<html>代码,获取notesRichTextItem内容信息的方法...


     前段时间用lotus写了个内容发布系统,使用notesRichTextItem保存内容。首页有个栏目块需要抽取文章的摘要信息(也就前多少个字符),手动输入的内容没问题,可以正常抽取;可是用户有时候在文档的前面插了个图片,或是从Word、网页上复制下来的信息贴进去保存之后,notesRichTextItem里面的内容就会带有<html>代码格式,抽取数据时数据、格式的问题就来了,晕啊。

     在网上找到一个解决办法,就是在Lotusscript代理中调用正则将得到的内容先替换,然后再截取内容片断。

具体代码如下(用于window平台):

 

Class RegExp
' RegExp -- use VBScript RegExp object to provide regular expressions
' 2004-06-03 David Phillips, rfdinc.com First version.
 
 Public matches As Variant
 Public oRegExp As Variant
 
 ' VBScript RegExp properties
 Public Pattern As String
 Public IgnoreCase As Boolean ' default = False
 Public Global As Boolean ' default = False
 
 Sub new ()
  Set oRegExp = CreateObject ("VBScript.RegExp")
 End Sub
 
 Public Function Match (source As String, pattern As String) As Boolean
 ' RegEx.Match -- scan source for pattern, set matches collection and return true if any
 ' (Can't call it Execute as that collides with LotusScript built-in function and statement.)
  With oRegExp
   .Pattern = pattern ' regular expression to match
   .IgnoreCase = IgnoreCase
   .Global = Global
   Set matches = .Execute (source) ' do match
   Match = (Not 0 = matches.count)
  End With
 End Function
 
 Public Function Replaces (source As String, pattern As String, replacement As String) As String
 ' RegEx.Replaces -- scan source for pattern, if found substitute replacement, return result
 ' (Can't call it Replace as that collides with LotusScript built-in function.)
  With oRegExp
   .Pattern = pattern
   .IgnoreCase = IgnoreCase
   .Global = Global
   Replaces = .Replace (source, replacement) ' do replace
  End With
 End Function
 
 Public Function Test (source As String, pattern As String) As Boolean
 ' RegEx.Test -- scan source for pattern, return true if found
  With oRegExp
   .Pattern = pattern
   .IgnoreCase = IgnoreCase
   Test = .Test (source)
  End With
 End Function 

 
End Class

 

-----------------------然后这样进行调用---------------------------------------------------

Dim re As New RegExp
re.IgnoreCase = True ' 设置是否区分字符大小写。
re.Global = True ' 设置全局可用性。

Gst = re.Replaces (Gst, "<[^>]+>", "") '删除所有html标签

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值