Encodes characters from the specified String into the specified byte array. : ASCIIEncoding « Internationalization I18N « VB.Net






Encodes characters from the specified String into the specified byte array.

 


Imports System
Imports System.Text
Imports Microsoft.VisualBasic.Strings

Class ASCIIEncodingExample
    Public Shared Sub Main()
        Dim bytes() As Byte
        ' ChrW(928) = Pi
        ' ChrW(931) = Sigma
        Dim chars() As Char = {ChrW(928), ChrW(931)}

        Dim ascii As New ASCIIEncoding()

        Dim byteCount As Integer = ascii.GetByteCount(chars, 1, 2)
        bytes = New Byte(byteCount - 1){}
        Dim bytesEncodedCount As Integer = ascii.GetBytes(chars, 1, 2, bytes, 0)

        Console.WriteLine("{0} bytes used to encode characters.", bytesEncodedCount)

        Dim b As Byte
        For Each b In bytes
            Console.Write("[{0}]", b)
        Next b
    End Sub
End Class

   
  








Related examples in the same category

1.ASCIIEncoding Class represents an ASCII character encoding of Unicode characters.
2.ASCIIEncoding Class Represents an ASCII character encoding of Unicode characters.
3.Decode bytes back to string
4.Get positions of the special characters
5.Create ASCIIEncoding class.
6.ASCIIEncoding.GetByteCount calculates the number of bytes produced by encoding a set of characters
7.ASCIIEncoding.GetByteCount (String)
8.Encodes characters from the specified character array into the specified byte array.
9.Calculates the number of characters produced by decoding bytes
10.Decodes bytes into the specified character array.
11.Calculates the maximum number of bytes produced by encoding the specified number of characters.
12.Calculates the maximum number of characters produced by decoding the specified number of bytes.
13.Decodes a range of bytes from a byte array into a string.