C#中的不区分大小写比较 [英] Case Insensitive comparison in C#

查看:286
本文介绍了C#中的不区分大小写比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am comparing two strings using following code

string1.Contains(string2)

string1.Contains(string2)

无法获取不区分大小写的搜索结果。此外,我不能使用String.Compare coz我不想匹配的整个名称,因为名称是非常大的。
我需要有不区分大小写的搜索,搜索文本可以是String1包含的任何长度。

but i am not getting results for case insensitive search. Moreover I cant use String.Compare coz i dont want to match the whole name as the name is very big. My need is to have case insensitive search and the search text can be of any length which the String1 contains.

Eg term * * ** ** 名字。
我在文本框中输入erm,得到结果。但是当我输入term我没有得到任何结果。
任何人都可以帮助我:)

Eg Term************** is the name. I enter "erm" in textbox den i get the result. but when i enter "term" i dont get any result. Can anyone help me :)

推荐答案

string.Equals ,ThIs WiLL ReTurN TRue,StringComparison.CurrentCultureIgnoreCase)

或,包含

if(string1.IndexOf(string2,StringComparison.CurrentCultureIgnoreCase)> = 0)

这篇关于C#中的不区分大小写比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆