使String.Contains()不区分大小写

时间:2018-06-05 14:08:03

标签: string vb.net visual-studio-2010

我在vb.net上制作了一个具有特定用途的软件。

它必须在特定点比较两个字符串,比如它们是x和y。代码是

If x.Contains(y) then
'do things here
End If

如果y是'Hello'而x是'hello there',则if语句必须根据我的要求为true,但事实证明Contains()控件区分大小写。

如何使其不区分大小写?

编辑: 我的问题是在vb.net而不是C#。虽然它们大多相似,但我不了解C#并且不知道如何在我的场景中实现答案,因为这两者都是不同的语言。所以我的问题与提到的问题不重复。

2 个答案:

答案 0 :(得分:1)

If x.IndexOf(y, StringComparison.CurrentCultureIgnoreCase) >= 0 Then
    'do nothing
End If

答案 1 :(得分:0)

将x和y都设为大写也适用。

If x.ToUpper().Contains(y.ToUpper()) Then
'do things here
End If