开发者

How to overcome case sensitive problem with contains method.?

开发者 https://www.devze.com 2022-12-23 13:45 出处:网络
Is there any solution to overcome case-sensiti开发者_Go百科ve problem for contains method. I have code like below

Is there any solution to overcome case-sensiti开发者_Go百科ve problem for contains method.

I have code like below

string str = m_name;
return avobj.Viewname.Contains(str);

Eg: Welcome Here welcome here

Both are same names but case is different. If I give 'W' in search box it is returning only 1st one. but I need both names display.

I am storing the names in collection. And resultant values ( searched values ) are storing in List.


You can use String.IndexOf(string, StringComparison). If it returns anything other than -1, then the substring was present. You can then specify an appropriately case-insensitive comparison.


public static bool ContainsCaseInsensitive(this string source, string value)
{
  int results = source.IndexOf(value, StringComparison.CurrentCultureIgnoreCase);
  return results != -1;
}

Source: http://schleichermann.wordpress.com/2009/02/24/c-stringcontains-case-insensitive-extension-method/

0

精彩评论

暂无评论...
验证码 换一张
取 消