Solved

Ignore Case in c#

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET Web API or ASP.NET Core MVC? 3 55
Export import database 4 45
C# parent child form 5 20
Video Player 2017 5 17
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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

864 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

20 Experts available now in Live!

Get 1:1 Help Now