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

14 篇文章 2 订阅
14 篇文章 0 订阅

全部代码:


```vbnet
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
效果:
![执行结果](https://img-blog.csdnimg.cn/img_convert/7da5a7ee86773119a5fcd16d8bf1225d.png)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

闪星2

Time is money

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值