Char.IsSurrogate Method

Definition

指示字符是否具有代理项代码单位。Indicates whether a character has a surrogate code unit.

Overloads

IsSurrogate(Char)

指示指定的字符是否具有指定的代理项代码单位。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.

IsSurrogate(Char)

指示指定的字符是否具有指定的代理项代码单位。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

Parameters

c
Char

要计算的 Unicode 字符。The Unicode character to evaluate.

Returns

Boolean

如果 true 为高代理项或低代理项,则为 c;否则为 falsetrue if c is either a high surrogate or a low surrogate; otherwise, false.

Examples

下面的示例演示 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

Remarks

代理项是一个具有 UTF-16 代码单元的 Char 对象,范围是从 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. 有关代理项对的详细信息,请参阅unicode 主页上的 unicode 标准。For more information about surrogate pairs, see the Unicode Standard at the Unicode home page.

See also

IsSurrogate(String, Int32)

指示指定字符串中位于指定位置的字符是否具有代理项代码单位。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

Parameters

s
String

一个字符串。A string.

index
Int32

s 中要计算的字符的位置。The position of the character to evaluate in s.

Returns

Boolean

如果 true 中位于 index 的字符是一个高代理项或低代理项,则为 s;否则为 falsetrue if the character at position index in s is a either a high surrogate or a low surrogate; otherwise, false.

Exceptions

snulls is null.

index 小于零或大于 s 中最后一个位置。index is less than zero or greater than the last position in s.

Examples

下面的代码示例演示 IsSurrogateThe 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

Remarks

字符串中的字符位置从零开始索引。Character positions in a string are indexed starting from zero.

代理项是一个具有 UTF-16 代码单元的 Char 对象,范围是从 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. 有关代理项对的详细信息,请参阅unicode 主页上的 unicode 标准。For more information about surrogate pairs, see the Unicode Standard at the Unicode home page.

See also

Applies to