Solved

Ignore Case in c#

Posted on 2009-04-08
2
1,358 Views
Last Modified: 2012-08-13

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

0
Comment
Question by:onebite2
  • 2
2 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24100602
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

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 24100612
The latter part should have read:

// And if you import the System.IO namespace you could do
 
Path.GetExtension(filename).Equals(".gpg", StringComparison.CurrentCultureIgnoreCase)

as GetExtension includes the dot (.)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question