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.

2
  • Can you add some examples of 'problem' strings and what you want them to do. The given information is pretty basic. Commented Apr 17, 2012 at 10:35
  • possible duplicate of Case insensitive contains(string) Commented Jun 21, 2012 at 14:17

2 Answers 2

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
}
Sign up to request clarification or add additional context in comments.

1 Comment

Worked Perfect, it even returns more items than windows explorer!
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.