Remove NULLs

  • Thread starter Thread starter buc
  • Start date Start date
B

buc

I have created a byte array (1000 in size) to recv a network packet. I recv
the packet, which varies in size, and need to put the packet in a string; so
I can append another string after the packet string. The problem is the
packet string apparently has nulls or something in the unused space up to
1000. and of course when I append a string AFTER the packet string it
doesn't display.How can I stick a b yte array into a string removing the
random number of nulls at the end. I tried to get the len of the packet
string and copy it, but it always returns 1000 regardless of the packet
size. I've tried different variations of
Encoding.ASCII.GetString(RecvBytes).ToString
but that copies the nulls too, and creates a new string of len 1000, with
the first x number of chars actually having valid data in it..
Thanks ...
BUC
 
Hi buc

When you call the Read() method on the Stream object, you'll notice that the
signature looks like this:

Public Function Read(ByVal bytes As Byte(), ByVal start As Integer, ByVal
length As Integer) As Integer

The return value is the number of bytes that were actually read...

HTH

Nigel Armstrong
 
buc,
In addition to Nigel's comments.
but that copies the nulls too, and creates a new string of len 1000, with
the first x number of chars actually having valid data in it..

Encoding.GetString has two overloads, you may want to consider using the
second overload:


Overloads Public Overridable Function GetString(Byte()) As String

Overloads Public Overridable Function GetString(Byte(), Integer, Integer) As
String

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top