Convert

Convert


Provides methods used to encode and decode byte arrays to and from base-64 encoded characters.


Remarks

To access the methods of this class, simply call the method using the Convert.* syntax.

'This example takes a byte array containing 10 values
'from 1 to 10 and encodes it into a Base-64 string encoding.
'The encoded string is then decoded back into the original
'byte array and displayed for view.

Private Sub Main()
    Dim original() As Byte
    Dim decoded() As Byte
    Dim s As String

    ' Create a byte array containing values 1 to 10.
    original = Cor.NewBytes( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

    ' Display the original byte array values
    Console.WriteLine "Original Bytes"
    DisplayBytes original

    ' Encode the byte array into a Base-64 Encoded string.
    s = Convert.ToBase64String(original)

    ' Display Base-64 Encoded string.
    Console.WriteLine
    Console.WriteLine "Base-64 Encoded String"
    Console.WriteLine " " & s

    ' Decode Base-64 string into byte array.
    decoded = Convert.FromBase64String(s)

    ' Display decoded byte array.
    Console.WriteLine "Bytes After Decoding"
    DisplayBytes decoded

    ' Wait for user to press enter
    Console.ReadLine
End Sub

'Displays the contents of a byte array.
Private Sub DisplayBytes(ByRef bytes() As Byte)
    Dim i As Long

    For i = LBound(bytes) To UBound(bytes)
        Console.WriteValue " " & bytes(i)
    Next i
End Sub

'This code produces the following output.

'original bytes
' 1 2 3 4 5 6 7 8 9 10
'Base-64 Encoded String
' AQIDBAUGBwgJCg==
'Bytes After Decoding
' 1 2 3 4 5 6 7 8 9 10
 

See Also

Project VBCorLib Overview

Public:

Methods:

NameDescription
 FromBase64CharArrayDecodes a base-64 character array to a byte array. The Offset and length specify a subset of the character array to be decoded. 
 FromBase64StringA base-64 string containing characters to be decoded to a byte array. 
 ToBase64CharArrayConverts the value of a subset of a byte array to an equivalent subset of a Unicode character array consisting of base 64 digits. Parameters specify the subsets as offsets of the input and output arrays and the number of elements in the input array. 
 ToBase64StringConverts the value of a subset of a byte array to an equivalent subset of a Unicode character string consisting of base-64 characters. Parameters specify the subsets as offsets of the input array and the number of elements in the input array to process. 
 ToStringConverts a datatype value to a string representation using any supplied formatting or provider arguments.