2

I need to search a directory for files and folders that contain the entered text,

I can see that File.Name.Contains(txtSearch) is the one that i need, but the problem is that it doesn't return true when characters cases (lower/upper) don't match.

Although File.Name.Equals(txtSearch,StringComparison.InvariantCultureIgnoreCase) solves this problem it requires that the the search string should be exactly the same.

Robin Maben
  • 22,194
  • 16
  • 64
  • 99
Murhaf Sousli
  • 12,622
  • 20
  • 119
  • 185
  • Can you add some examples of 'problem' strings and what you want them to do. The given information is pretty basic. – CodingBarfield Apr 17 '12 at 10:35
  • possible duplicate of [Case insensitive contains(string)](http://stackoverflow.com/questions/444798/case-insensitive-containsstring) – Damith Jun 21 '12 at 14:17

2 Answers2

3
var position =  File.Name.IndexOf(txtSearch, StringComparison.InvariantCultureIgnoreCase)

Where position will be greater than -1 if your "file name" contains any occurrence of the specified search string.

So..

if(position > -1){
    //found files, do something
}
Robin Maben
  • 22,194
  • 16
  • 64
  • 99
0
 var _reps = new List<string>(); // with variant data

_reps.ConvertAll<string>(new Converter<string,string>(delegate(string srt){srt= srt.ToLower(); return srt;})).Contains("invisible")

this is by far the cleanest way i could find to do it

j0k
  • 22,600
  • 28
  • 79
  • 90
Uhlamurile
  • 29
  • 1