title: C# .Net framework strings encoding from utf-8 bytes
body: <p>I have application wrote in C#, and this application receives data through network from server using sockets (udp libenet).</p>
  <p>In my application I have function to process raw bytes sent in packet.
  One of functions is reading string, delimited by \0.</p>
  <p>My problem is that I'm sending UTF-8 encoded string by server to C# application, but when I use these strings to display them in controls, I get gibberish instead of polish letters.</p>
  <p>Function that reads strings from buffer:</p>
  <pre><code>public override string ReadString()
  {
              
      StringBuilder sb = new StringBuilder();
  
      while (true)
      {
          byte b;
          if (Remaining &gt; 0)
              b = ReadByte();
          else
              b = 0;
  
          if (b == 0) break;
  
          // Probably here is the problem. Checked other encodings etc., but still same 
          sb.Append(Encoding.UTF8.GetString(new byte[] { b }, 0, 1));
      }
  
      return sb.ToString();
  }
  </code></pre>
  <p>Function overrides, the one from:</p>
  <pre><code>public class BitReader : BinaryReader
  </code></pre>
  <p>In my application I get:</p>
  <p><a href="https://i.stack.imgur.com/X0Hyv.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X0Hyv.jpg" alt="Polish letters turned into gibberish in dataviewgrid" /></a></p>