C# Char IsHighSurrogate(String, Int32)
Description
Char IsHighSurrogate(String, Int32)
indicates whether
the Char object at the specified position in a string is a high surrogate.
Syntax
Char.IsHighSurrogate(String, Int32)
has the following syntax.
public static bool IsHighSurrogate(
string s,
int index
)
Parameters
Char.IsHighSurrogate(String, Int32)
has the following parameters.
s
- A string.index
- The position of the character to evaluate in s.
Returns
Char.IsHighSurrogate(String, Int32)
method returns true if the numeric value of the specified character in the s parameter ranges
from U+D800 through U+DBFF; otherwise, false.
Example
The following code example demonstrates the IsHighSurrogate method.
using System;/* w w w . j a v a 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 characters a high surrogate?");
Console.WriteLine("A1) cLow? - {0}", Char.IsHighSurrogate(cLow));
Console.WriteLine("A2) cHigh? - {0}", Char.IsHighSurrogate(cHigh));
Console.WriteLine("A3) s1[0]? - {0}", Char.IsHighSurrogate(s1, 0));
Console.WriteLine("A4) s1[1]? - {0}", Char.IsHighSurrogate(s1, 1));
}
}
The code above generates the following result.