Encoding.UTF8 : UTF8Encoding « Internationalization I18N « VB.Net






Encoding.UTF8

 

Imports System
Imports System.Text
Imports Microsoft.VisualBasic

Public Class SamplesEncoding   

   Public Shared Sub Main()
      Dim myChars() As Char = {ChrW(&HD8FF), ChrW(&HDCFF)}

      Dim u8 As Encoding = Encoding.UTF8
      PrintCountsAndBytes(myChars, u8)

   End Sub 'Main
   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

1.Calculates number of characters produced by decoding a sequence of bytes from the specified byte array.
2.Decodes a sequence of bytes from the specified byte array into the specified character array.
3.Obtains a decoder that converts a UTF-8 encoded sequence of bytes into a sequence of Unicode characters.
4.UTF-8 encoding of Unicode characters.
5.Create UTF8Encoding class
6.Create UTF8Encoding class.
7.UTF8Encoding.Equals