加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

VB6 正则表达式提取内容

发布时间:2020-12-17 07:42:47 所属栏目:百科 来源:网络整理
导读:今天帮同事做一个数据对接,从返回的数据中提取想要的部分。返回的是一个WebService结果,由外圈的XML标记和中间的有效内容组成,现在要把有效内容取出来,VB6.0实现。 下面是返回的内容: ?xml version='1.0' encoding='UTF-8'?soapenv:Envelope xmlns:soap

今天帮同事做一个数据对接,从返回的数据中提取想要的部分。返回的是一个WebService结果,由外圈的XML标记和中间的有效内容组成,现在要把有效内容取出来,VB6.0实现。

下面是返回的内容:

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:getAllQuickInfoResponse xmlns:ns="http://webservice.sp.action.org" xmlns:ax21="http://service.webservice.sp.action.org/xsd">
<ns:return>
[...省略]
</ns:return>
</ns:getAllQuickInfoResponse>
</soapenv:Body>
</soapenv:Envelope>

要把中间的有效内容取出来。想到了正则表达式,在VB6中用法如下:

首先要添加正则表达式的引用:

菜单栏: “工程” - “引用” - “Microsoft VBScript Regular Expressions 5.5”


用法:

'获取有效内容
  Dim str As String
  
  Dim re As RegExp
  Dim mh As Match
  Dim mhs As MatchCollection
    
  str = HttpClient.responseText
  Set re = New RegExp
 
  re.Pattern = "[.*]"
  Set mhs = re.Execute(str)
  Set mh = mhs(0)

  MsgBox (mh.Value)

效果:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读