Qassam Mahmoud
Qassam Mahmoud

Reputation: 147

how to convert string to byte() vb.net?

error msg i got : system.byte{}

code :

Module Module1

Sub Main()

    Dim qassam As String = "mylove"
    Dim lena As Byte() = System.Text.Encoding.Default.GetBytes(qassam)

    Console.WriteLine(lena)


    Console.ReadLine()


End Sub

End Module

Upvotes: 2

Views: 21237

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460018

You have successfully encoded the string into a byte(). But you can't output this byte-array with Console.WriteLine because then only the type-name is written.

You could use:

Console.WriteLine(String.Join(",", lena))

On .NET 2.0 you could use this approach:

Dim lenaStrings = Array.ConvertAll(lena, Function(b) b.ToString())
Console.WriteLine(String.Join(",", lenaStrings))

Upvotes: 2

Related Questions