您的位置:首页 > 编程语言 > VB

获取字符串中 某个字符或者某个字符串的个数

2016-05-05 11:55 295 查看
全部代码:

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


效果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息