全部代码:
Module Module1
Sub Main()
Debug.Print($"过程:{New StackTrace().GetFrame(0).GetMethod.Name} 方法1")
Dim str = "7f 7f 00 00 ad 00 00 00 00 00 0d 0a 00 00 00 ad"
Dim adCount = UBound(Split(str,"ad"))
Debug.Print($"过程:{New StackTrace().GetFrame(0).GetMethod.Name} ad的个数:{adCount}")
For Each ad In Split(str,"ad")
Debug.Print($"过程:{New StackTrace().GetFrame(0).GetMethod.Name} 用ad分割出来的结果分别是:{ad}")
Next
Debug.Print($"过程:{New StackTrace().GetFrame(0).GetMethod.Name} 方法2")
Dim adQuery = From ad In Split(str," ")
Where ad.ToLowerInvariant() = "ad".ToLowerInvariant()
Select ad
Debug.Print($"过程:{New StackTrace().GetFrame(0).GetMethod.Name} ad的个数:{adQuery.Count}")
Debug.Print($"过程:{New StackTrace().GetFrame(0).GetMethod.Name} 方法3")
Debug.Print($"过程:{New StackTrace().GetFrame(0).GetMethod.Name} ad的个数:{Split(str," ").Count(Function(ad) ad = "ad")}")
End Sub
End Module
效果: