When trying to display a byte stream from HLDS (Half-Life Dedicated Server) in a textbox, it displays strange blocky question mark characters that look something like this:
[?]
Here's a sample line from the byte stream (with [?] in place of the strange character):
CPU In Out Uptime Users FPS Players[?] 0.00 0.97 0.91 2806 182 297.25 1[?]
Here is how I display the byte stream as a string:
byte[] bytes = listener.Receive(ref sender); // get bytes from stream
TextBox1.Text = Encoding.ASCII.GetString(bytes, 0, bytes.Length); // write to textbox
The characters are appearing where [CR][LF]
should normally appear. Why is it showing strange characters, and what can I do to remove the weird characters or correct the encoding?
***** UPDATE *****
Jon Skeet provided the right answer. The logs are returning \n for newline (not \r\n) and \0 at the end of each log line streamed. Replaced \n with Environment.NewLine and \0 with string.Empty and the strange characters are gone. Thank you Jon.