![]() |
String concatenation having null character
Hi to all
I'm trying to concatenate a array of bytes (0-255) to a single string, like this: Private conteudoBytes(2000) As Byte Private conteudoStr As String When I try to do: For i = 0 To 2000 conteudoStr = conteudoStr & Chr(conteudoBytes(i)) Next i conteudoStr have the concatenated string to the first null character (0x00), exclusively. I don't know why it stops there. conteudoBytes(2000) have the contents of a binary file. Am i doing this the wrong way? Sincere regards and thank you in advance for reading, Marco |
String concatenation having null character
Maybe something like this:
Private conteudoBytes(2000) As Byte Private conteudoStr*2001 As String For i = 0 To 2000 if conteudoBytes(i) < 0 then Mid(conteudoStr,i+1,1) = Chr(conteudoBytes(i)) end if Next i -- Regards, Tom Ogilvy "marco" wrote: Hi to all I'm trying to concatenate a array of bytes (0-255) to a single string, like this: Private conteudoBytes(2000) As Byte Private conteudoStr As String When I try to do: For i = 0 To 2000 conteudoStr = conteudoStr & Chr(conteudoBytes(i)) Next i conteudoStr have the concatenated string to the first null character (0x00), exclusively. I don't know why it stops there. conteudoBytes(2000) have the contents of a binary file. Am i doing this the wrong way? Sincere regards and thank you in advance for reading, Marco |
String concatenation having null character
Are you sure that it stops there? If you were testing things by the
message box function, the msgbox function won't display past a null character - but the data is there in the string nevertheless: Sub test() Dim S As String S = "Hello" & Chr(0) & "World" Debug.Print S 'prints "Hello World" in the immediate window MsgBox S 'just displays "Hello" MsgBox Mid(S, 7) 'displays "World" - the data is there and still extractable MsgBox Len(S) 'displays 11 End Sub Hth -John Coleman On Mar 12, 2:30 pm, "marco" wrote: Hi to all I'm trying to concatenate a array of bytes (0-255) to a single string, like this: Private conteudoBytes(2000) As Byte Private conteudoStr As String When I try to do: For i = 0 To 2000 conteudoStr = conteudoStr & Chr(conteudoBytes(i)) Next i conteudoStr have the concatenated string to the first null character (0x00), exclusively. I don't know why it stops there. conteudoBytes(2000) have the contents of a binary file. Am i doing this the wrong way? Sincere regards and thank you in advance for reading, Marco |
String concatenation having null character
Are you sure that it stops there? If you were testing things by the
message box function, the msgbox function won't display past a null character - but the data is there in the string nevertheless: Sub test() Dim S As String S = "Hello" & Chr(0) & "World" Debug.Print S 'prints "Hello World" in the immediate window MsgBox S 'just displays "Hello" MsgBox Mid(S, 7) 'displays "World" - the data is there and still extractable MsgBox Len(S) 'displays 11 End Sub Hth -John Coleman On Mar 12, 2:30 pm, "marco" wrote: Hi to all I'm trying to concatenate a array of bytes (0-255) to a single string, like this: Private conteudoBytes(2000) As Byte Private conteudoStr As String When I try to do: For i = 0 To 2000 conteudoStr = conteudoStr & Chr(conteudoBytes(i)) Next i conteudoStr have the concatenated string to the first null character (0x00), exclusively. I don't know why it stops there. conteudoBytes(2000) have the contents of a binary file. Am i doing this the wrong way? Sincere regards and thank you in advance for reading, Marco |
String concatenation having null character
That's it !!
MsgBox() doesn't show chr(0), but the Immediate Window does. Thanks alot, you saved me of alot of (debugging) time. Thanks to all of you. Marco On Mar 12, 8:47 pm, "John Coleman" wrote: Are you sure that it stops there? If you were testing things by the message box function, the msgbox function won't display past a null character - but the data is there in the string nevertheless: Sub test() Dim S As String S = "Hello" & Chr(0) & "World" Debug.Print S 'prints "Hello World" in the immediate window MsgBox S 'just displays "Hello" MsgBox Mid(S, 7) 'displays "World" - the data is there and still extractable MsgBox Len(S) 'displays 11 End Sub Hth -John Coleman On Mar 12, 2:30 pm, "marco" wrote: Hi to all I'm trying to concatenate a array of bytes (0-255) to a single string, like this: Private conteudoBytes(2000) As Byte Private conteudoStr As String When I try to do: For i = 0 To 2000 conteudoStr = conteudoStr & Chr(conteudoBytes(i)) Next i conteudoStr have the concatenated string to the first null character (0x00), exclusively. I don't know why it stops there. conteudoBytes(2000) have the contents of a binary file. Am i doing this the wrong way? Sincere regards and thank you in advance for reading, Marco- Hide quoted text - - Show quoted text - |
All times are GMT +1. The time now is 05:23 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com