Solved

Ignore Case in c#

Posted on 2009-04-08
2
1,346 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 74

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 74

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now