zoukankan      html  css  js  c++  java
  • 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标签

  • 相关阅读:
    Jenkins修改用户密码及权限
    Selenium知识点小结
    解析图形验证码登录系统
    Pywinauto实现电脑客户端有道云签到领空间
    Python冒泡排序
    LoadRunner12常用函数
    GIT教程笔记
    LoadRunner 关联
    搭建自动化测试框架Python3+Selenium
    SSH免密从A服务器登录进B服务器,重启B服务器的tomcat
  • 原文地址:https://www.cnblogs.com/hannover/p/2311524.html
Copyright © 2011-2022 走看看