Can anyone help me converting a string into byte array.
Lets say i have string "Hello world" and i want to convert it, copy it to byte array.
Printable View
Can anyone help me converting a string into byte array.
Lets say i have string "Hello world" and i want to convert it, copy it to byte array.
Do you want each character's ascii value to be assigned to the corresponding array element? If yes, this is one way you can do it:Quote:
Originally Posted by Dungeon Keeper
Code:Dim s As String
Dim b() As Byte
s = "Hi babe"
ReDim b(1 To Len(s))
For i = 1 To Len(s)
b(i) = Asc(Mid(s, i, 1))
Debug.Print b(i)
Next
Hey, thanx krtxmrtz.
Im doing it that way, but i have added -1 to len, because array begins from 0.
Everything works fine, but i still have problems with this.
Im using winsock to transfer files and when i save the file it is 1kb larger than original. It works fine, but it is larger, why is that. I thought im not converting correctly.
Sorry I'm not much familiar with winsock so my advice is, since this is a different problem, start a new thread.Quote:
Originally Posted by Dungeon Keeper
Code:Dim s As String
Dim b() As Byte
s = "Hello, World!"
b = StrConv(s, vbFromUnicode)