Convert a String to a Byte Array in VB.Net

I had a snippet on my site for converting a byte array to a string, but I didn’t have anything for going the other way.

This function should do the trick.

Public Shared Function StringByByteArray(ByVal s As String) As Byte()
    Return System.Text.Encoding.UTF8.GetBytes(s)
End Function

Leave a comment