Skip to content

Malfunction: byte 256 to string

Jacob R

Asked Feb 7, 2010, 9:48 PM EST1 answer
Share
LinkedInX
I'm getting a byte array from a server on the return it is set up like..
byte[] myBytes = new byte[256];
Now when I try to convert it to a string with ASCIIEncoding it get the string and then I get the rest of the 256 characters as /0/0/0/0/0 ect...  I've tried
string.Replace("\\0", ""); and it didn't take them away.  I've also tried .Remove() but once It hits the .Indexof("\\0") I get an error like they aren't even there. 
To encode I tried:
s = new string(Encoding.ASCII.GetChars(myBytes));
s = ASCIIEncoding.ASCII.GetString(myBytes);
s = Encoding.ASCII.GetString(myBytes, 0, myBytes.Length);
and nothing seems to work to get rid of all of the /0/0/0's
help me plz

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Well, it turns out they are some hidden blank spaces in the string but they aren't exactly " " <-- spaces.  I just did a foreach loop to go through all of the characters in the string and if they are 0-9, a-z or A-Z then I added them to a string builder.  What a pain in my rear!
    0