CompareInfo.GetSortKey Method

Definition

Gets a SortKey object for a string.

Overloads

GetSortKey(String)

Gets the sort key for the specified string.

GetSortKey(String, CompareOptions)

Gets a SortKey object for the specified string using the specified CompareOptions value.

GetSortKey(ReadOnlySpan<Char>, Span<Byte>, CompareOptions)

Computes a sort key for the specified input.

GetSortKey(String)

Source:
CompareInfo.cs
Source:
CompareInfo.cs
Source:
CompareInfo.cs

Gets the sort key for the specified string.

public System.Globalization.SortKey GetSortKey (string source);
public virtual System.Globalization.SortKey GetSortKey (string source);

Parameters

source
String

The string for which a SortKey object is obtained.

Returns

The SortKey object that contains the sort key for the specified string.

Remarks

Each character in a string is given several categories of sort weights, including script, alphabetic, case, and diacritic weights. A sort key is the repository of these weights for a particular string. For example, a sort key might contain a string of alphabetic weights, followed by a string of case weights, and so on. The GetSortKey method is equivalent to the Windows API method LCMapString with the LCMAP_SORTKEY flag.

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

GetSortKey(String, CompareOptions)

Source:
CompareInfo.cs
Source:
CompareInfo.cs
Source:
CompareInfo.cs

Gets a SortKey object for the specified string using the specified CompareOptions value.

public System.Globalization.SortKey GetSortKey (string source, System.Globalization.CompareOptions options);
public virtual System.Globalization.SortKey GetSortKey (string source, System.Globalization.CompareOptions options);

Parameters

source
String

The string for which a SortKey object is obtained.

options
CompareOptions

A bitwise combination of one or more of the following enumeration values that define how the sort key is calculated: IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidth, IgnoreKanaType, and StringSort.

Returns

The SortKey object that contains the sort key for the specified string.

Exceptions

options contains an invalid CompareOptions value.

Remarks

Each character in a string is given several categories of sort weights, including script, alphabetic, case, and diacritic weights. A sort key is the repository of these weights for a particular string. For example, a sort key might contain a string of alphabetic weights, followed by a string of case weights, and so on. The GetSortKey method is equivalent to the Windows API method LCMapString with the LCMAP_SORTKEY flag.

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

GetSortKey(ReadOnlySpan<Char>, Span<Byte>, CompareOptions)

Source:
CompareInfo.cs
Source:
CompareInfo.cs
Source:
CompareInfo.cs

Computes a sort key for the specified input.

public int GetSortKey (ReadOnlySpan<char> source, Span<byte> destination, System.Globalization.CompareOptions options = System.Globalization.CompareOptions.None);

Parameters

source
ReadOnlySpan<Char>

The text to get the sort key for.

destination
Span<Byte>

The buffer into which the resulting sort key bytes are stored.

options
CompareOptions

An optional combination of CompareOptions enumeration values to use for computing the sort key. The default value is None.

Returns

The number of bytes written to destination.

Exceptions

destination is too small to contain the resulting sort key; or options contains an unsupported flag; or source cannot be processed using the desired CompareOptions under the current CompareInfo.

Remarks

Use GetSortKeyLength(ReadOnlySpan<Char>, CompareOptions) to query the required size of destination. It is acceptable to provide a larger-than-necessary output buffer to this method.

Applies to

.NET 9 and other versions
Product Versions
.NET 5, 6, 7, 8, 9