Lire en anglais Modifier

Partager via


Char.IsSurrogate Method

Definition

Indicates whether a character has a surrogate code unit.

Overloads

IsSurrogate(String, Int32)

Indicates whether the character at the specified position in a specified string has a surrogate code unit.

IsSurrogate(Char)

Indicates whether the specified character has a surrogate code unit.

Examples

The following example demonstrates the IsSurrogate method.

using System;

public class IsSurrogateSample {
    public static void Main() {
        string str = "\U00010F00"; // Unicode values between 0x10000 and 0x10FFF are represented by two 16-bit "surrogate" characters

        Console.WriteLine(Char.IsSurrogate('a'));		// Output: "False"
        Console.WriteLine(Char.IsSurrogate(str, 0));	// Output: "True"
    }
}

IsSurrogate(String, Int32)

Source:
Char.cs
Source:
Char.cs
Source:
Char.cs

Indicates whether the character at the specified position in a specified string has a surrogate code unit.

public static bool IsSurrogate (string s, int index);

Parameters

s
String

A string.

index
Int32

The position of the character to evaluate in s.

Returns

true if the character at position index in s is a either a high surrogate or a low surrogate; otherwise, false.

Exceptions

index is less than zero or greater than the last position in s.

Remarks

Character positions in a string are indexed starting from zero.

A surrogate is a Char object with a UTF-16 code unit in the range from U+D800 to U+DFFF. Each character with a code unit in this range belongs to the UnicodeCategory.Surrogate category. The individual surrogate code unit has no interpretation of its own, but has meaning only when used as part of a surrogate pair. For more information about surrogate pairs, see the Unicode Standard at the Unicode home page.

See also

Applies to

.NET 9 et autres versions
Produit Versions
.NET Core 1.0, Core 1.1, 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 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

IsSurrogate(Char)

Source:
Char.cs
Source:
Char.cs
Source:
Char.cs

Indicates whether the specified character has a surrogate code unit.

public static bool IsSurrogate (char c);

Parameters

c
Char

The Unicode character to evaluate.

Returns

true if c is either a high surrogate or a low surrogate; otherwise, false.

Remarks

A surrogate is a Char object with a UTF-16 code unit in the range from U+D800 to U+DFFF. Each character with a code unit in this range belongs to the UnicodeCategory.Surrogate category. The individual surrogate code unit has no interpretation of its own, but has meaning only when used as part of a surrogate pair. For more information about surrogate pairs, see the Unicode Standard at the Unicode home page.

See also

Applies to

.NET 9 et autres versions
Produit Versions
.NET Core 1.0, Core 1.1, 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 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0