RE: Help converting Buffer of Bytes to string



You can Null terminate a byte array by

vo = Encoding.ASCII.GetBytes("Test")
ReDim Preserve vo(vo.Length)


"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
> >
> >
> >
.



Relevant Pages

  • I dont mind bug: BinToHex implementation/description do not match !
    ... The BinToHex procedure occurding to Delphi's help would return a 'null' ... to terminate it with a #0 in the first place. ... Call BinToHex to convert the binary value in a buffer into a string that is ... Buffer is a buffer of bytes that contains the binary value. ...
    (alt.comp.lang.borland-delphi)
  • Re: Data type byte
    ... attempt to change the input buffer to a string (although not by changing the ... With multi dimensional array that can hold ... Also the receiving ... dimensional Byte Array is just one long string of memory. ...
    (microsoft.public.vb.general.discussion)
  • Re: String parsing in VB.net
    ... refactor your code so that myDataBuffer is an array of Byte, ... than a string. ... receives a data buffer. ... encoding - it is only defined for 0-127. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: from array of ints to string and vice versa
    ... I want to convert this string to an array, ... other to generate it, separating them with ", ". ... takes a buffer and returns a size, which you first call with a NULL pointer ...
    (comp.programming)
  • Re: I dont mind bug: BinToHex implementation/description do not match !
    ... assigning it to another string you may see this problem. ... > forgets to add a null terminated character. ... > to terminate it with a #0 in the first place. ... > Buffer is a buffer of bytes that contains the binary value. ...
    (alt.comp.lang.borland-delphi)

Loading