title: How to detect end of string in byte array to string conversion?
body: <p>I receive from socket a string in a byte array which look like : </p>
  
  <pre><code>[128,5,6,3,45,0,0,0,0,0]
  </code></pre>
  
  <p>The size given by the network protocol is the total lenght of the string (including zeros) so , in my exemple 10.</p>
  
  <p>If i simply do : </p>
  
  <pre><code>String myString = new String(myBuffer); 
  </code></pre>
  
  <p>I have at the end of the string 5 non correct caracter. The conversion don't seems to detect the end of string caracter (0).</p>
  
  <p>To get the correct size and the correct string i do this : </p>
  
  <pre><code>int sizeLabelTmp = 0;
  //Iterate over the 10 bit to get the real size of the string
  for(int j = 0; j&lt;(sizeLabel); j++) {
      byte charac = datasRec[j];
      if(charac == 0)
          break;
      sizeLabelTmp ++;
  }
  // Create a temp byte array to make a correct conversion
  byte[] label    = new byte[sizeLabelTmp];
  for(int j = 0; j&lt;(sizeLabelTmp); j++) {
      label[j] = datasRec[j];
  }
  String myString = new String(label);
  </code></pre>
  
  <p>Is there a better way to handle the problem ?</p>
  
  <p>Thanks</p>