Solved

Ignore Case in c#

Posted on 2009-04-08
2
1,376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

636 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