简体   繁体   English

VB.NET LIKE 字符串比较运算符等价于 C#

[英]VB.NET LIKE string comparison operator equivalent in C#

I'm a new developer in C# and I'm migrating code from VB.NET to C#. But the LIKE operator is not working in C#, is there another one with the same function?我是 C# 的新开发人员,我正在将代码从 VB.NET 迁移到 C#。但是 LIKE 运算符在 C# 中不起作用,是否有另一个具有相同 function 的?

The VB.NET code I need to convert looks like this::我需要转换的 VB.NET 代码如下所示:

If (item Like "[A-D]") Then

    End If

    If (item Like "[E-H]") Then

    End If

    If (item Like "[I-M]") Then

    End If

    If (item Like "[N-V]") Then

    End If

LIKE operator does not exist for C#, the solution is to use regular expression. C#不存在LIKE运算符,解决方法是使用正则表达式。

try this:尝试这个:

if (Regex.IsMatch(item, "^[a-dA-D]+$"))
        {

        }

        if (Regex.IsMatch(item, "^[e-hE-H]+$"))
        {

        }

        if (Regex.IsMatch(item, "^[i-mI-M]+$"))
        {

        }

        if (Regex.IsMatch(item, "^[n-vN-V]+$"))
        {

        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM