Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Char.IsLowSurrogate Method (String, Int32)

Indicates whether the Char object at the specified position in a string is a low surrogate.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
'Declaration
Public Shared Function IsLowSurrogate ( _
	s As String, _
	index As Integer _
) As Boolean

Parameters

s
Type: System.String

A string.

index
Type: System.Int32

The position of the character to evaluate in s.

Return Value

Type: System.Boolean
true if the numeric value of the specified character in the s parameter ranges from U+DC00 through U+DFFF; otherwise, false.
ExceptionCondition
ArgumentNullException

s is Nothing.

ArgumentOutOfRangeException

index is not a position within s.

The index parameter is zero-based.

In addition to representing single characters using a 16-bit code point, UTF-16 encoding allows abstract characters to be represented using two 16-bit code points, which is known as a surrogate pair. The second element in this pair is the low surrogate. Its code point can range from U+DC00 to U+DFFF. 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.IsLowSurrogate() method 
'                                    IsHighSurrogate() method 
'                                    IsSurrogatePair() method 
Imports System
Imports Microsoft.VisualBasic

Class Sample
   Public Shared Sub Main()
      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(Environment.NewLine, _
                                              New [String]("-"c, 70), _
                                              Environment.NewLine)

      Console.WriteLine()
      Console.WriteLine("Hexadecimal code point of the character, cHigh: {0:X4}", AscW(cHigh))
      Console.WriteLine("Hexadecimal code point of the character, cLow:  {0:X4}", AscW(cLow))
      Console.WriteLine()
      Console.WriteLine("Characters in string, s1: 'a', high surrogate, low surrogate, 'z'")
      Console.WriteLine("Hexadecimal code points of the characters in string, s1: ")
      Dim i As Integer 
      For i = 0 To s1.Length - 1
         Console.WriteLine("s1({0}) = {1:X4} ", i, AscW(s1.Chars(i)))
      Next i
      Console.WriteLine(divider)

      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))
      Console.WriteLine(divider)

      Console.WriteLine("Is each of the following characters a low surrogate?")
      Console.WriteLine("B1) cLow?  - {0}", [Char].IsLowSurrogate(cLow))
      Console.WriteLine("B2) cHigh? - {0}", [Char].IsLowSurrogate(cHigh))
      Console.WriteLine("B3) s1(0)? - {0}", [Char].IsLowSurrogate(s1, 0))
      Console.WriteLine("B4) s1(2)? - {0}", [Char].IsLowSurrogate(s1, 2))
      Console.WriteLine(divider)

      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))
      Console.WriteLine(divider)
   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 characters a high surrogate? 
'A1) cLow?  - False 
'A2) cHigh? - True 
'A3) s1(0)? - False 
'A4) s1(1)? - True 

'---------------------------------------------------------------------- 

'Is each of the following characters a low surrogate? 
'B1) cLow?  - True 
'B2) cHigh? - False 
'B3) s1(0)? - False 
'B4) s1(2)? - True 

'---------------------------------------------------------------------- 

'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 

'---------------------------------------------------------------------- 
'

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft. All rights reserved.