This question already has answers here:
Case insensitive 'Contains(string)'

(27个答案)


7年前关闭。




我正在使用以下代码比较两个字符串

string1。包含(string2)

但我没有获得不区分大小写的搜索结果。此外,我不能使用String.Compare因为我的名字很大,所以我不想匹配整个名字。
我需要不区分大小写的搜索,并且搜索文本的长度可以是String1包含的任何长度。

例如Term * ************** 是名称。
我在文本框中输入“erm”,但没有得到结果。但是当我输入“term”时,我没有任何结果。
谁能帮我 :)

最佳答案

string.Equals("this will return true", "ThIs WiLL ReTurN TRue", StringComparison.CurrentCultureIgnoreCase)
或者,对于包含
if (string1.IndexOf(string2, StringComparison.CurrentCultureIgnoreCase) >= 0)

关于c# - C#中不区分大小写的比较,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10797309/

10-13 00:00