String.Compare Method Home
This page is specific to:.NET Framework Version:1.12.03.03.5Silverlight 34.0
.NET Framework Class Library
String.Compare Method

Compares two specified String objects.

Overload List

Name Description
String.Compare (String, String) Compares two specified String objects.

Supported by the .NET Compact Framework.

String.Compare (String, String, Boolean) Compares two specified String objects, ignoring or honoring their case.

Supported by the .NET Compact Framework.

String.Compare (String, String, StringComparison) Compares two specified String objects. A parameter specifies whether the comparison uses the current or invariant culture, honors or ignores case, and uses word or ordinal sort rules.

Supported by the .NET Compact Framework.

String.Compare (String, String, Boolean, CultureInfo) Compares two specified String objects, ignoring or honoring their case, and using culture-specific information to influence the comparison.

Supported by the .NET Compact Framework.

String.Compare (String, Int32, String, Int32, Int32) Compares substrings of two specified String objects.

Supported by the .NET Compact Framework.

String.Compare (String, Int32, String, Int32, Int32, Boolean) Compares substrings of two specified String objects, ignoring or honoring their case.

Supported by the .NET Compact Framework.

String.Compare (String, Int32, String, Int32, Int32, StringComparison) Compares substrings of two specified String objects.

Supported by the .NET Compact Framework.

String.Compare (String, Int32, String, Int32, Int32, Boolean, CultureInfo) Compares substrings of two specified String objects, ignoring or honoring their case, and using culture-specific information to influence the comparison.

Supported by the .NET Compact Framework.

See Also

Community Content

Please specify what kind of comparison you expect :) Use StringComparison or CultureInfo!
Added by:Shawn Steele [MSFT]

Please specify what kind of comparison you expect :)  Use StringComparison, or CultureInfo if necessary

Some applications need linguistic comparisons, others need ordinal type comparisons.  A very general rule would be that user facing comparisons would need linguistic comparisons (use current culture), and security comparisons may need ordinal or ordinal ignore case.  For some applilcations the default comparisons will not be appropriate.  It is much better to understand the differences and use the correct version.

Additionally note that it is challenging to try to figure out what is going to be a match for the file system, URI/IRIs, etc.  It is generally preferable to use the specific comparisons for the resource you're trying to compare.  For example ?, & and other escaping rules in URLs, ..\, .\, :, etc in file names, etc. could all cause unexpected behavior if not properly tested for.

Comparison Results
Added by:Mike Hohm

I'm not sure why this is not already posted, but here is the logic table for the comparison results in general:

parameter 1 < parameter 2 = -1

parameter 1 > parameter 2 = 1

parameter 1 = parameter 2 = 0

The linked documents tell more. I'm not sure why I need to click on each overload, unless one returns different values. If that is the case, it probably needs a seperate method name.

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View