C# Char IsSurrogatePair(String, Int32)

Description

Char IsSurrogatePair(String, Int32) indicates whether two adjacent Char objects at a specified position in a string form a surrogate pair.

Syntax

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


public static bool IsSurrogatePair(
  string s,
  int index
)

Parameters

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

  • s - A string.
  • index - The starting position of the pair of characters to evaluate within s.

Returns

Char.IsSurrogatePair(String, Int32) method returns true if the s parameter includes adjacent characters at positions index and index + 1, and the numeric value of the character at position index ranges from U+D800 through U+DBFF, and the numeric value of the character at position index+1 ranges from U+DC00 through U+DFFF; otherwise, false.

Example

The following code example demonstrates the IsSurrogatePair method.


using System;//from w ww . j  a va 2s  .  c om

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