peet
asked on
Convert String <--> Byte Array ?
How do you convert a Byte Array to a String ?
( Without moving big chunks of data )
I have :
Dim anArray(4096) As Byte
Dim StringData As String
I use the Win API
ReadFile(h, anArray(0),BytesToRead, BytesRead, 0) to read the data. I then want to transmit the data with the WinSock
control:
StringData <-- anArray ????????????????
tcpServer.SendData StringData
Your help would be appreciated.
Peet
( Without moving big chunks of data )
I have :
Dim anArray(4096) As Byte
Dim StringData As String
I use the Win API
ReadFile(h, anArray(0),BytesToRead, BytesRead, 0) to read the data. I then want to transmit the data with the WinSock
control:
StringData <-- anArray ????????????????
tcpServer.SendData StringData
Your help would be appreciated.
Peet
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
MyString = ""
FOR ndx = 0 to 4095
MyString = MyString & CHR( anArray( ndx ) )
NEXT ndx
FOR ndx = 0 to 4095
MyString = MyString & CHR( anArray( ndx ) )
NEXT ndx
ASKER
karmi,
Thanks a lot for the help
peet
Thanks a lot for the help
peet
A byte in VB is like a small integer rather than a char
There may be a way of doing this, but it would be using the Win API
4097 bytes is a small chunk of data
Dim anArray(4) As Byte ' 5 byte array (0 to 4)
Dim StringData As String
Dim i As Integer
anArray(0) = Asc("H")
anArray(1) = Asc("e")
anArray(2) = Asc("l")
anArray(3) = Asc("l")
anArray(4) = Asc("o")
'StringData = CStr(anArray()) 'This will not work
For i = LBound(anArray) To UBound(anArray)
StringData = StringData & Chr$(anArray(i))
Next i
MsgBox StringData