tags:

views:

69

answers:

3

hi

how to notice if "abcDEf" different that "abcdef" ?

in C# winforms ?

thank's in advance

+2  A: 
bool aredifferent = "abcDEf" != "abcdef";
//OR
string str1 = "abcDEf", str2 = "abcdef";
bool aredifferent2 = str1 != str2;

.NET string equality operator is case sensitive, so simply using it will return false if string differ in case.

If, however, you are looking to determining if two strings are the same, but only differ in case, then you could use something like this:

bool differInCase = string.Compare(str1, str2, /*ignoreCase=*/true) == 0 &&
                    string.Compare(str1, str2, /*ignoreCase=*/false) != 0;;
Igor Zevaka
+1  A: 

Since you're in Winforms, i'm assuming you're using System^ String. They come with an "Equals" member to take care of this situation.

http://msdn.microsoft.com/en-us/library/1hkt4325.aspx

System::String::Equals( str1, str2 )

This returns a System::Boolean which is true/false.

Edit Sorry, i've been doing Winforms in C++ for too long..here's C#

System.String.Equals(a, b)

Still returns a System Boolean which is true/false.

Edit Edit

If you're looking to do a Current culture case-insensitive equal's check:

System.String.Equals(a,b,System.StringComparison.CurrentCultureIgnoreCase)

Check this MSDN page for all the info on the StringComparison enumeration:

http://msdn.microsoft.com/en-us/library/system.stringcomparison.aspx

Caladain
`::`? [ ](http://stackoverflow.com/questions/3385268/how-to-notice-if-abcdef-different-that-abcdef)
Kobi
Ack, good catch. I've been doing Winforms with Managed C++..but a system string is a system string :-D
Caladain
Please, call it C++/CLI and not *Managed C++*. *Managed Extensions for C++* is the older, Visual Studio 2002-era language which was a real mess and full of bugs.
Ben Voigt
Fair Enough. All my literature calls it Managed C++, but i got no issue calling it C++/CLI. A duck is a duck no matter what you call it :-)
Caladain
When I hear "Managed C++", by default I think of "Managed C++ that doesn't suck - i.e. C++/CLI"... Just my 2c.
Igor Zevaka
A: 

Are you looking for something like this?

function IsLowerCase(String input)
{
    return input.Equals( input.ToLower() );
}

This function will return false if the input string is in mixed or upper case. If instead the input string is in lower case then it will return true.

Anax