您可以将 .Contains(string) 与 Select Case 语句一起使用吗?

发布于 2024-08-29 17:25:10 字数 164 浏览 6 评论 0原文

无论如何,我可以构建一个使用 Contains 函数的 Select 语句吗?像这样:

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

Is there anyway I can build a Select statement that uses the Contains function? Like this:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明天过后 2024-09-05 17:25:10
Select Case True
    Case commentStr.Contains("10")
        'foo
    Case commentStr.Contains("15")
        'bar
End Select

请注意,使用此构造,最多将执行一个 Case

(另请注意,您的 C# 朋友无法使用 switch 执行此操作,这需要 case 子句中的常量表达式:))

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 :))

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文