Char.IsHighSurrogate Method (Char)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Indicates whether the specified Char object is a high surrogate.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- c
- Type: System.Char
The Unicode character to evaluate.
Return Value
Type: System.Booleantrue if the numeric value of the c parameter ranges from U+D800 through U+DBFF; otherwise, false.
In addition to representing single characters using a 16-bit code unit, UTF-16 encoding allows abstract characters to be represented using two 16-bit code units, which is known as a surrogate pair. The first element in this pair is the high surrogate. Its code point can range from U+D800 to U+DBFF. An individual surrogate has no interpretation of its own; it is meaningful only when used as part of a surrogate pair.
The following code example demonstrates the IsHighSurrogate, IsLowSurrogate, and IsSurrogatePair methods.
' This example demonstrates the Char.IsSurrogatePair() method Class Example Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) Dim cHigh As Char = ChrW(&HD800) Dim cLow As Char = ChrW(&HDC00) Dim s1 = New [String](New Char() {"a"c, ChrW(&HD800), ChrW(&HDC00), "z"c}) Dim divider As String = [String].Concat(vbCrLf, _ New [String]("-"c, 70), _ vbCrLf) outputBlock.Text &= vbCrLf outputBlock.Text &= String.Format("Hexadecimal code point of the character, cHigh: {0:X4}", AscW(cHigh)) & vbCrLf outputBlock.Text &= String.Format("Hexadecimal code point of the character, cLow: {0:X4}", AscW(cLow)) & vbCrLf outputBlock.Text &= vbCrLf outputBlock.Text &= String.Format("Characters in string, s1: 'a', high surrogate, low surrogate, 'z'") & vbCrLf outputBlock.Text &= String.Format("Hexadecimal code points of the characters in string, s1: ") & vbCrLf Dim i As Integer For i = 0 To s1.Length - 1 outputBlock.Text &= String.Format("s1({0}) = {1:X4} ", i, AscW(s1.Chars(i))) & vbCrLf Next i outputBlock.Text &= divider & vbCrLf outputBlock.Text &= "Is each of the following pairs of characters a surrogate pair?" & vbCrLf outputBlock.Text &= String.Format("C1) cHigh and cLow? - {0}", [Char].IsSurrogatePair(cHigh, cLow)) & vbCrLf outputBlock.Text &= String.Format("C2) s1(0) and s1(1)? - {0}", [Char].IsSurrogatePair(s1, 0)) & vbCrLf outputBlock.Text &= String.Format("C3) s1(1) and s1(2)? - {0}", [Char].IsSurrogatePair(s1, 1)) & vbCrLf outputBlock.Text &= String.Format("C4) s1(2) and s1(3)? - {0}", [Char].IsSurrogatePair(s1, 2)) & vbCrLf outputBlock.Text &= divider & vbCrLf End Sub 'Main End Class 'Sample ' 'This example produces the following results: ' 'Hexadecimal code point of the character, cHigh: D800 'Hexadecimal code point of the character, cLow: DC00 ' 'Characters in string, s1: 'a', high surrogate, low surrogate, 'z' 'Hexadecimal code points of the characters in string, s1: 's1(0) = 0061 's1(1) = D800 's1(2) = DC00 's1(3) = 007A ' '---------------------------------------------------------------------- ' 'Is each of the following pairs of characters a surrogate pair? 'C1) cHigh and cLow? - True 'C2) s1(0) and s1(1)? - False 'C3) s1(1) and s1(2)? - True 'C4) s1(2) and s1(3)? - False ' '----------------------------------------------------------------------