Link to home
Start Free TrialLog in
Avatar of onebite2
onebite2

asked on

Ignore Case in c#


Is there a way to ignore the case in the below line like using compare options.ignore case  or anything???
Becaue the file name could either be in upper or lower case..I have the line of code to grab lower case ...but I just want to change it so that it ignores case.....how should I change this??

Thanks!!
if (_config.Encrypted && fileName.Substring(fileName.LastIndexOf(".") + 1).ToLower() == "gpg")

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

The Equals() method of the string class has some options of interest:
fileName.Substring(fileName.LastIndexOf(".") + 1).Equals("gpg", StringComparison.CurrentCultureIgnoreCase)
 
// And if you import the System.IO namespace you could do
 
Path.GetExtension(filename).Equals("gpg", StringComparison.CurrentCultureIgnoreCase)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial