Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42215

How to remove NULL spaces from an Array or String

$
0
0
I'll try to be as precise as possible.

I have a TCP Server, a TCP Client, both of them sends bytes to each others and store them into an Array upon arrival.
This Array contains the string i sent from the Server + about 8100 characters represented by 0 in bytes.
Then, the Array is converted into a string and when you output it, it shows a normal string.

But this string is fact 8100 characters long so if i try using it with a Select Case, it never works even tho the string outputted is exactly the same.
What i wanna do is ignore all the bytes equal to 0 and store everything else into an array but, another problem arise.

You can't create an empty array in Visual Basic, you can either specify it's size or add items to it right away and, i don't know how long the array is gonna be.
Also, if i make a new array equals to 1000 just to be safe, the same problem arise but now, my string is equal to 1000+ characters.

How can i fix this? I've spent 6 hours trying different things, i even asked on stackoverflow but nobody knows what to do.

If somebody can help, I'll be forever grateful.


TCP Server :

vb Code:
  1. Try
  2.  
  3.     Dim bytes() As Byte = System.Text.Encoding.ASCII.GetBytes(requestedAction)
  4.    _TCPServer.Send(bytes)
  5.  
  6. Catch ex As Exception
  7. End Try

TCP Client :

vb Code:
  1. If _TCPStream.DataAvailable Then
  2.  
  3.    Dim rcvdbytes(_TCPClient.ReceiveBufferSize) As Byte
  4.    _TCPStream.Read(rcvdbytes, 0, CInt(_TCPClient.ReceiveBufferSize))
  5.    Dim request As String = System.Text.Encoding.ASCII.GetString(rcvdbytes)
  6.  
  7.    Execute_Action(request) 'Info sent to Select Case
  8.  
  9. End If

Viewing all articles
Browse latest Browse all 42215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>