玩酷之家

 找回密码
 立即注册
查看: 210|回复: 1

VB 获取两个标签之间的数据

[复制链接]
发表于 2021-1-8 15:45:46 | 显示全部楼层 |阅读模式
  1. Private Sub Command1_Click()
  2. On Error Resume Next
  3. Text1.Text = "<MemberInfo><online_count>0天0小时27分</online_count></MemberInfo>"
  4. Text1.Text = TestRegExp2(Text1.Text)
  5. End Sub

  6. Function TestRegExp2$(myString As String)
  7. Dim objRegExp As RegExp '定义对象
  8. Dim objMatch As Match
  9. Dim colMatches As MatchCollection '对象包含有关匹配字符串的信息
  10. Dim RetStr As String
  11. Dim hanzi As String
  12. Set objRegExp = New RegExp
  13. objRegExp.Pattern = "<online_count>(.*)</online_count>" '传入参数,用来定义正则表达式
  14. objRegExp.IgnoreCase = True
  15. objRegExp.Global = True
  16. If objRegExp.Test(myString) Then '正则表达式与字符串成功匹配
  17. Set colMatches = objRegExp.Execute(myString)
  18. For Each objMatch In colMatches
  19. RetStr = RetStr & objMatch.SubMatches(0) & vbCrLf
  20. Next
  21. Else
  22. RetStr = "String Matching Failed"
  23. End If
  24. TestRegExp2 = RetStr
  25. End Function
复制代码


回复

使用道具 举报

发表于 2021-3-13 23:58:26 | 显示全部楼层

用法  MidStr("12132<Table>Test!</Table>12321", "<Table>", "</Table>")

  1. Public Function MidStr(ByVal str As String, ByVal StartStr As String, ByVal EndStr As String, Optional ByVal Order As Integer = 0) As String
  2.    
  3.     Dim L As Long, r As Long
  4.     L = InStr(str, StartStr)
  5.     If L = 0 Then Exit Function
  6.     L = L + Len(StartStr)
  7.     If Order = 0 Then
  8.         r = InStr(L, str, EndStr)
  9.     Else
  10.         r = InStrRev(str, EndStr)
  11.     End If
  12.     If r < L Then Exit Function
  13.     MidStr = Mid(str, L, r - L)
  14. End Function

复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|玩酷之家 ( 鄂ICP备14012049号 )

GMT+8, 2021-4-22 10:52 , Processed in 1.092002 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表