C# Char IsSurrogatePair(Char, Char)

Description

Char IsSurrogatePair(Char, Char) indicates whether the two specified Char objects form a surrogate pair.

Syntax

Char.IsSurrogatePair(Char, Char) has the following syntax.


public static bool IsSurrogatePair(
  char highSurrogate,
  char lowSurrogate
)

Parameters

Char.IsSurrogatePair(Char, Char) has the following parameters.

  • highSurrogate - The character to evaluate as the high surrogate of a surrogate pair.
  • lowSurrogate - The character to evaluate as the low surrogate of a surrogate pair.

Returns

Char.IsSurrogatePair(Char, Char) method returns true if the numeric value of the highSurrogate parameter ranges from U+D800 through U+DBFF, and the numeric value of the lowSurrogate parameter ranges from U+DC00 through U+DFFF; otherwise, false.

Example

The following code example demonstrates the IsSurrogatePair method.


using System;/*from  ww w  .  j  a  va  2  s .c o  m*/

class Sample 
{
    public static void Main() 
    {
        char cHigh = '\uD800';
        char cLow  = '\uDC00';
        string s1  = new String(new char[] {'a', '\uD800', '\uDC00', 'z'});
    
        Console.WriteLine("Is each of the following pairs of characters a surrogate pair?");
        Console.WriteLine("C1) cHigh and cLow?  - {0}", Char.IsSurrogatePair(cHigh, cLow));
        Console.WriteLine("C2) s1[0] and s1[1]? - {0}", Char.IsSurrogatePair(s1, 0));
        Console.WriteLine("C3) s1[1] and s1[2]? - {0}", Char.IsSurrogatePair(s1, 1));
        Console.WriteLine("C4) s1[2] and s1[3]? - {0}", Char.IsSurrogatePair(s1, 2));
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version