Char.IsSurrogate Метод

Определение

Indicates whether a character has a surrogate code unit.Indicates whether a character has a surrogate code unit.

Перегрузки

IsSurrogate(Char)

Indicates whether the specified character has a surrogate code unit.Indicates whether the specified character has a surrogate code unit.

IsSurrogate(String, Int32)

Indicates whether the character at the specified position in a specified string has a surrogate code unit.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.Indicates whether the specified character has a surrogate code unit.

public:
 static bool IsSurrogate(char c);
public static bool IsSurrogate (char c);
static member IsSurrogate : char -> bool
Public Shared Function IsSurrogate (c As Char) As Boolean

Параметры

c
Char

The Unicode character to evaluate.The Unicode character to evaluate.

Возвращаемое значение

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

Примеры

В следующем примере демонстрируется метод IsSurrogate.The following example demonstrates the IsSurrogate method.

using namespace System;
int main()
{
   
   // - escape params specifying Unicode not implemented in v7.0
   Console::WriteLine( Char::IsSurrogate( 'a' ) ); // Output: "False"
}

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"
    }
}
Module IsSurrogateSample

    Sub Main()

        ' NOTE: Visual Basic doesn't give us a way to create a 32-bit Unicode 
        ' character composed of two 16-bit surrogate values, so a case where 
        ' IsSurrogate returns True cannot be included in this sample. 

        Console.WriteLine(Char.IsSurrogate("a"c))       ' Output: "False"

    End Sub

End Module

Комментарии

Суррогат — это Char объект с единицей кода UTF-16 в диапазоне от U + D800 до U + DFFF.A surrogate is a Char object with a UTF-16 code unit in the range from U+D800 to U+DFFF. Каждый символ с единицей кода в этом диапазоне принадлежит к категории UnicodeCategory.Surrogate.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.

Дополнительно

IsSurrogate(String, Int32)

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

public:
 static bool IsSurrogate(System::String ^ s, int index);
public static bool IsSurrogate (string s, int index);
static member IsSurrogate : string * int -> bool
Public Shared Function IsSurrogate (s As String, index As Integer) As Boolean

Параметры

s
String

A string.A string.

index
Int32

The position of the character to evaluate in s.The position of the character to evaluate in s.

Возвращаемое значение

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

Исключения

s is null.s is null.

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

Примеры

В следующем примере кода демонстрируется IsSurrogate.The following code example demonstrates IsSurrogate.

using namespace System;
int main()
{
   
   // - escape params specifying Unicode not implemented in v7.0
   Console::WriteLine( Char::IsSurrogate( 'a' ) ); // Output: "False"
}

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"
    }
}
Module IsSurrogateSample

    Sub Main()

        ' NOTE: Visual Basic doesn't give us a way to create a 32-bit Unicode 
        ' character composed of two 16-bit surrogate values, so a case where 
        ' IsSurrogate returns True cannot be included in this sample. 

        Console.WriteLine(Char.IsSurrogate("a"c))       ' Output: "False"

    End Sub

End Module

Комментарии

Позиции символов в строке индексируются начиная с нуля.Character positions in a string are indexed starting from zero.

Суррогат — это Char объект с единицей кода UTF-16 в диапазоне от U + D800 до U + DFFF.A surrogate is a Char object with a UTF-16 code unit in the range from U+D800 to U+DFFF. Каждый символ с единицей кода в этом диапазоне принадлежит к категории UnicodeCategory.Surrogate.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.

Дополнительно

Применяется к