I have a byte array similar to this (16 bytes):
71 77 65 72 74 79 00 00 00 00 00 00 00 00 00 00
I use this to convert it to a string and tr
Why try to create the string first and trim it second? This could add a lot of overhead (if the byte[] is large).
You can specify index
and count
in the GetString(byte[] bytes, int index, int count)
overload.
int count = data.Count(bt => bt != 0); // find the first null
string result = Encoding.ASCII.GetString(data, 0, count); // Get only the characters you want