|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Help converting Buffer of Bytes to stringI note that you can null teminate a string by adding controlchar.null.
Is there a way of adding a null to a Buffer of Bytes and converting it to a string. I have packets coming in from a serial ports as bytes and some of these represent strings. (Like the Packed BCD date/time stamp etc). At present I read through each Byte and convert to char and append to a string. In C, you can simply place a null at any position in he buffer and copy the entire buffer to a string variable. Can this be dome in VB .NET ? Thanks I have a similar problem. I am calling a C API on a PocketPC using VB.NET.
The function declaration is Declare Function newVo Lib "Test.dll" Alias "newVo" _ (ByRef hVo As IntPtr, ByVal hInstance As integer, ByVal ByVal vo() As Byte, ByVal Rate As UInt32, ByVal coding As String) As Integer I call it like this. Dim vo() As Byte vo = Encoding.ASCII.GetBytes("Test") ret = api.ttsNewVo(hVo, hInstance.ToInt32, vo, 16000, "L") In have a log file enabled and it should list "Test.vde", but there is a binary 04 and 08 character following "Test" and before the ".vde". Do I need to NULL terminate the ASCII byte array or where are these extra characters coming from? What is the best way of adding a null to a Buffer of Bytes. Thanks Show quoteHide quote "David" wrote: > I note that you can null teminate a string by adding controlchar.null. > > Is there a way of adding a null to a Buffer of Bytes and converting it to a > string. > > I have packets coming in from a serial ports as bytes and some of these > represent strings. (Like the Packed BCD date/time stamp etc). > > At present I read through each Byte and convert to char and append to a > string. > > In C, you can simply place a null at any position in he buffer and copy the > entire buffer to a string variable. Can this be dome in VB .NET ? > > Thanks > > > You can Null terminate a byte array by
vo = Encoding.ASCII.GetBytes("Test") ReDim Preserve vo(vo.Length) Show quoteHide quote "smaggi" wrote: > I have a similar problem. I am calling a C API on a PocketPC using VB.NET. > The function declaration is > > Declare Function newVo Lib "Test.dll" Alias "newVo" _ > (ByRef hVo As IntPtr, ByVal hInstance As integer, ByVal > ByVal vo() As Byte, ByVal Rate As UInt32, ByVal coding > As String) As Integer > > I call it like this. > > Dim vo() As Byte > vo = Encoding.ASCII.GetBytes("Test") > ret = api.ttsNewVo(hVo, hInstance.ToInt32, vo, 16000, "L") > > In have a log file enabled and it should list "Test.vde", but there is a > binary 04 and 08 character following "Test" and before the ".vde". Do I need > to NULL terminate the ASCII byte array or where are these extra characters > coming from? > What is the best way of adding a null to a Buffer of Bytes. > > Thanks > > "David" wrote: > > > I note that you can null teminate a string by adding controlchar.null. > > > > Is there a way of adding a null to a Buffer of Bytes and converting it to a > > string. > > > > I have packets coming in from a serial ports as bytes and some of these > > represent strings. (Like the Packed BCD date/time stamp etc). > > > > At present I read through each Byte and convert to char and append to a > > string. > > > > In C, you can simply place a null at any position in he buffer and copy the > > entire buffer to a string variable. Can this be dome in VB .NET ? > > > > Thanks > > > > > >
Microsoft not content with "dissing" just the Classic VB Developer Army....
Where to find good icons? In-place Updating in Datagrid not working Why doesn't timer tick Event for PgUp and PgDn on Form How to get current free physical memory ? modify HTML in code behind How to expose a structure to VB6 from VB.NET? Datagrid problem How to convert a Byte array to a String |
|||||||||||||||||||||||