Is this a long way to compare strings ignoring the case?
if ( string.Compare(wsUri.Host, "localHost",
System.StringComparison.OrdinalIgnoreCase) == 0 )
{
// etc.
} 6 11283
<an******@hotmail.comwrote:
Is this a long way to compare strings ignoring the case?
if ( string.Compare(wsUri.Host, "localHost",
System.StringComparison.OrdinalIgnoreCase) == 0 )
{
// etc.
}
Well, it's easier to use
if ("localHost".Equals(wsUri.Host, StringComparison.OrdinalIgnoreCase))
(If you know that wsUri.Host is non-null, you can swap what the method
is called on for clarity.)
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Well it's long, but just as number of characters.
A shorter version could be string.Compare(wsUri.Host, "localHost",true)==0
It still takes three parameters.
<an******@hotmail.comha scritto nel messaggio
news:11**********************@h3g2000cwc.googlegro ups.com...
Is this a long way to compare strings ignoring the case?
if ( string.Compare(wsUri.Host, "localHost",
System.StringComparison.OrdinalIgnoreCase) == 0 )
{
// etc.
}
On Mar 2, 1:11 pm, "Laura T." <L...@NOWHERE.COMwrote:
Well it's long, but just as number of characters.
A shorter version could be string.Compare(wsUri.Host, "localHost",true)==0
It still takes three parameters.
<anoni...@hotmail.comha scritto nel messaggionews:11**********************@h3g2000cwc. googlegroups.com...
Is this a long way to compare strings ignoring the case?
if ( string.Compare(wsUri.Host, "localHost",
System.StringComparison.OrdinalIgnoreCase) == 0 )
{
// etc.
}- Hide quoted text -
- Show quoted text -
wsUri.Host.ToString().ToUpper().Equals("LOCALHOST" ) would be much
simpler i think
-
shashank kadge
On Mar 6, 3:40 pm, "shashank kadge" <mailtosha...@gmail.comwrote:
>
wsUri.Host.ToString().ToUpper().Equals("LOCALHOST" ) would be much
simpler i think
It's not guaranteed to work though, due to potential culture issues.
I ran into a problem years ago where I was trying to compare strings
in a case-insensitive way by doing the above - and we found that in
Turkey, we had a problem, because the upper case of "i" isn't "I" in
Turkey (and vice versa).
Using a case-insensitive comparison is the best way of working.
Jon
On Mar 6, 11:49 am, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
On Mar 6, 3:40 pm, "shashank kadge" <mailtosha...@gmail.comwrote:
wsUri.Host.ToString().ToUpper().Equals("LOCALHOST" ) would be much
simpler i think
It's not guaranteed to work though, due to potential culture issues.
I ran into a problem years ago where I was trying to compare strings
in a case-insensitive way by doing the above - and we found that in
Turkey, we had a problem, because the upper case of "i" isn't "I" in
Turkey (and vice versa).
Using a case-insensitive comparison is the best way of working.
Jon
Got u Jon. thanks.
-
shashank kadge
A nice shorthand overload is:
String.Compare(wsUri.Host, "localHost", true) == 0 ...
--
HTH,
Kevin Spencer
Microsoft MVP
Help test our new betas,
DSI PrintManager, Miradyne Component Libraries: http://www.miradyne.net
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
On Mar 6, 3:40 pm, "shashank kadge" <mailtosha...@gmail.comwrote:
>> wsUri.Host.ToString().ToUpper().Equals("LOCALHOST ") would be much simpler i think
It's not guaranteed to work though, due to potential culture issues.
I ran into a problem years ago where I was trying to compare strings
in a case-insensitive way by doing the above - and we found that in
Turkey, we had a problem, because the upper case of "i" isn't "I" in
Turkey (and vice versa).
Using a case-insensitive comparison is the best way of working.
Jon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Will McGugan |
last post by:
What is the best way to do a simple case insensitive comparison in Python?
As far as I can tell, the only option is to do str1.lowercase() ==
str2.lowercase() (or uppercase). But that strikes me...
|
by: ajay.sonawane |
last post by:
How can I find the wheather the occurance substring is main string in
wide char provided that the compasion should be case insensitive.
|
by: Ron James |
last post by:
I have a Listbox containing strings. When calling Contains
(), I would like a case insensitive comparison. (I don't
want to add newfile.txt to a Listbox containing
NewFile.txt).
I'm...
|
by: Jan Nielsen |
last post by:
Hi all
I am learning Asp.Net using Vb.net (VS 2002).
I found the following example in a book:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles...
|
by: Mark Rae |
last post by:
Hi,
Is it possible to create a case-insensitive List<stringcollection?
E.g.
List<stringMyList = new List<string>;
MyList.Add("MyString");
So that:
| |
by: benhoefer |
last post by:
I have been searching around and have not been able to find any info
on this. I have a unique situation where I need a case sensitive map:
std::map<string, intimap;
I need to be able to run a...
|
by: Coder Guy |
last post by:
Is it possible to do a case insensitive comparison of individual characters?
I tried:
Char.ToLowerInvariant(charA).CompareTo(Char.ToLowerInvariant(charB))
And though it works for the most...
|
by: Mosfet |
last post by:
Hi,
what is the most efficient way of doing a case insensitive comparison ?
I am trying to write a universal String class and I am stuck with the
case insensitive part :
TCHAR is a char in...
|
by: Chris Rebert |
last post by:
On Thu, Sep 4, 2008 at 3:37 PM, Robert Dailey <rcdailey@gmail.comwrote:
Then store the string in its original case in the value part of the
key-value pair:
stage_map = (key,whatever)
- Chris
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |