title: Remove trailing zeros from byte[]?
body: <p>I'm working with TCP protocol and read from socket and write the data to a byte[] array.<br>
  Here is a example of my data:  </p>
  
  <pre><code>94 39 E5 D9 32 83
  D8 5D 4C B1 CB 99 
  08 00 45 00 00 98 
  41 9F 40 00 6C 06 
  9C 46 26 50 48 7D 
  C0 A8 01 05 03 28
  </code></pre>
  
  <p>I created a byte[] array with size of 1024. Now I use this method to remove null indexes from it:  </p>
  
  <pre><code>public void Decode(byte[] packet)
  {
      byte[] temp;
      int c = 0;
      foreach(byte x in packet)
          if (x != 0)
              c++;
      temp = new byte[c];
      for (int i = 0; i &lt; c; i++)
          temp[i] = packet[i];
      MessageBox.Show(temp.Length.ToString());
  }
  </code></pre>
  
  <p>But it removes also 0x00 indexes that it maybe useful data...<br>
  How can I remove the 0s that are not wrapped with non-zero data (trailing 0s)?</p>