I need to convert a simple string in a Byte array using excel VBA. Then this byte array is used as the request's body.
How can I do that?
Matthew answered how to convert to ANSI, but if you wanted the resulting byte array to still represent the original Unicode string, you'd simply assign it directly:
Public Sub Main()
Dim b() As Byte
Dim s As String
s = "Whatever"
b = s 'Assign Unicode string to bytes.'
s = b 'Works in reverse, too!'
Debug.Print s
End Sub
That's all there is to it. You end up with a 16-element Byte array, each successive pair describing one Unicode character.
If you only need ANSI characters, you can use the StrConv() function as is done here.
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