Share via


How to: Convert Strings into an Array of Bytes in Visual BasicĀ 

This topic shows how to convert a string into an array of bytes.

Example

This example uses the GetBytes method of the System.Text.Encoding.Unicode encoding class to convert a string into an array of bytes.

Private Function UnicodeStringToBytes( _
    ByVal str As String) _
    As Byte()

    Return System.Text.Encoding.Unicode.GetBytes(str)
End Function

You can choose from several encoding options to convert a string into a byte array:

See Also

Tasks

How to: Convert an Array of Bytes into a String in Visual Basic

Reference

System.Text.Encoding
GetBytes