[英]VB.NET LIKE string comparison operator equivalent in C#
我是 C# 的新开发人员,我正在将代码从 VB.NET 迁移到 C#。但是 LIKE 运算符在 C# 中不起作用,是否有另一个具有相同 function 的?
我需要转换的 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
C#不存在LIKE运算符,解决方法是使用正则表达式。
尝试这个:
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.