C# Case insensitive string comparison
This question already has an answer here:
The Contains
method has an overload that accepts an IEqualityComparer
. You can give it one by doing the following:
if (list.Contains(test2, StringComparer.OrdinalIgnoreCase))
{
// do something
}
IndexOf has a parameter for case insensitive search
culture.CompareInfo.IndexOf(toSearch, word, CompareOptions.IgnoreCase)
where culture is the instance of CultureInfo describing the language that the text is written in.
You can loop through the list and see if it each list entry matches the search.
让你的list
小写......和
if (list.Contains(test2.ToLower()))
{
}
链接地址: http://www.djcxy.com/p/13088.html
上一篇: c#If else语句不区分大小写
下一篇: C#不区分大小写的字符串比较