Just a moment ago I create C# Server Socket application and using code below to convert byte[] message from my Client Socket Application into String.

dataFromClient = (System.Text.Encoding.ASCII.GetString(bytesFrom));

When I running the program and get message from the client, I have a byte array that may or may not have null bytes at the end of it. After converting it to a string I have a bunch of blank spaces at the end. I tried using Trim() to get rid of it, but it doesn’t work. After searching trough internet I figure it out, Trim() does not work in this case, because it only removes spaces, tabs and newlines AFAIK. It does not remove the ” character. So I tried add TrimEnd(“”) and hollaa now those blank spaces disappear.

dataFromClient = (System.Text.Encoding.ASCII.GetString(bytesFrom)).TrimEnd('\0');

Subscribe via twitter :