Encoding.BigEndianUnicode
Imports System
Imports System.Text
Imports Microsoft.VisualBasic
Public Class SamplesEncoding
Public Shared Sub Main()
Dim myChars() As Char = {ChrW(&HD8FF), ChrW(&HDCFF)}
Dim u16BE As Encoding = Encoding.BigEndianUnicode
PrintCountsAndBytes(myChars, u16BE)
End Sub
Public Shared Sub PrintCountsAndBytes(chars() As Char, enc As Encoding)
Console.Write("{0,-30} :", enc.ToString())
Dim iBC As Integer = enc.GetByteCount(chars)
Console.Write(" {0,-3}", iBC)
Dim iMBC As Integer = enc.GetMaxByteCount(chars.Length)
Console.Write(" {0,-3} :", iMBC)
Dim bytes As Byte() = enc.GetBytes(chars)
PrintHexBytes(bytes)
End Sub
Public Shared Sub PrintHexBytes(bytes() As Byte)
If bytes Is Nothing OrElse bytes.Length = 0 Then
Console.WriteLine("<none>")
Else
Dim i As Integer
For i = 0 To bytes.Length - 1
Console.Write("{0:X2} ", bytes(i))
Next i
End If
End Sub
End Class
Related examples in the same category