开发者

Can you use .Contains(string) with a Select Case Statement?

开发者 https://www.devze.com 2022-12-27 14:22 出处:网络
Is there anyway I can build a Select statement that uses the Contains function? L开发者_运维技巧ike this:

Is there anyway I can build a Select statement that uses the Contains function? L开发者_运维技巧ike this:

Select commentStr
    Case commentStr.Contains("10")
    Case commentStr.Contains("15")


Select Case True
    Case commentStr.Contains("10")
        'foo
    Case commentStr.Contains("15")
        'bar
End Select

Note that with this construct, a maximum of one Case will be executed.

(Also note that your C# friends can't do this with switch, which requires constant expressions in the case clauses :))

0

精彩评论

暂无评论...
验证码 换一张
取 消