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

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

发布时间:2020-12-17 07:39:15 所属栏目:百科 来源:网络整理
导读:全部代码: 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 ($ "过

全部代码:

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

效果:

(编辑:李大同)

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

    推荐文章
      热点阅读