Index | Next 

Conversions between String and Byte arrays

VB6 supports implicit conversions from String to Byte arrays, and vice versa, as in this code snippet:
        Dim s1 As String, s2 As String, b() As Byte
        s1 = "abcde"
        b = s1
        s2 = b
VB.NET doesn’t support such implicit conversions and requires explicit calls to methods of the System.Text.Encoding class:
        Dim s1 As String, s2 As String, b() As Byte
        s1 = "abcde"
        b = Encoding.Unicode.GetBytes(s1)
        s2 = Enconding.Unicode.GetString(b)
For uniformity and readability’s sake, VB Migration Partner generates calls to ByteArrayToString6 and StringToByteArray6 methods when the original code implicitly converts a Byte array to a String, or vice versa.

 

Index | Next