VB6 正则表达式提取内容

前端之家收集整理的这篇文章主要介绍了VB6 正则表达式提取内容前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

下面是返回的内容

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

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

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

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


用法

  1. '获取有效内容
  2. Dim str As String
  3. Dim re As RegExp
  4. Dim mh As Match
  5. Dim mhs As MatchCollection
  6. str = HttpClient.responseText
  7. Set re = New RegExp
  8. re.Pattern = "\[.*]"
  9. Set mhs = re.Execute(str)
  10. Set mh = mhs(0)
  11.  
  12. MsgBox (mh.Value)

效果

猜你在找的VB相关文章