This has to be incredibly simple, but I must not be looking in the right place.
I'm receiving this string via a FTDI usb connection:
'UUU'
I would like to receive this as a byte array of
[85,85,85]
In Python, this I would convert a string to a byte array like this: [ord(c) for c in 'UUU']
I've looked around, but haven't figured this out. How do I do this in Visual Basic?
Use the Encoding
class with the correct encoding.
C#:
// Assuming string is UTF8
Encoding utf8 = Encoding.UTF8Encoding();
byte[] bytes = utf8.GetBytes("UUU");
VB.NET:
Dim utf8 As Encoding = Encoding.UTF8Encoding()
Dim bytes As Byte() = utf8.GetBytes("UUU")
depends on what kind of encoding you want to use but for UTF8 this works, you could chane it to UTF16 if needed.
Dim strText As String = "UUU"
Dim encText As New System.Text.UTF8Encoding()
Dim btText() As Byte
btText = encText.GetBytes(strText)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With