How to convert one byte to string?
-
In MSDN guide convert array bytes to string, here code:
Encoding.UTF8.GetString(byte[] bytes)
VS2005 doesn't support convert one byte to string. Anybody can I help me? or for example how to convert one byte to string. Although, may be use toConvert.ToString(byte)
is correct, but I don't think so. Except, differently another way Thank one so much!!!! -
In MSDN guide convert array bytes to string, here code:
Encoding.UTF8.GetString(byte[] bytes)
VS2005 doesn't support convert one byte to string. Anybody can I help me? or for example how to convert one byte to string. Although, may be use toConvert.ToString(byte)
is correct, but I don't think so. Except, differently another way Thank one so much!!!!Encoding.UTF8.GetString(byte[] bytes) is working. did you try the method Tostring();
-
In MSDN guide convert array bytes to string, here code:
Encoding.UTF8.GetString(byte[] bytes)
VS2005 doesn't support convert one byte to string. Anybody can I help me? or for example how to convert one byte to string. Although, may be use toConvert.ToString(byte)
is correct, but I don't think so. Except, differently another way Thank one so much!!!! -
In MSDN guide convert array bytes to string, here code:
Encoding.UTF8.GetString(byte[] bytes)
VS2005 doesn't support convert one byte to string. Anybody can I help me? or for example how to convert one byte to string. Although, may be use toConvert.ToString(byte)
is correct, but I don't think so. Except, differently another way Thank one so much!!!!If you encode a single character into bytes using the UTF-8 encoding, it can result in more than a single byte. It wouldn't make sense to have a method that decodes a single byte, as that would only work on a very limited part of the character set. If you have a character that actually was encoded into a single byte, you just have to put that byte in an array to decode it. If you are trying to decode data byte by byte, that doesn't work, as some characters may need more than one byte of the data.
Despite everything, the person most likely to be fooling you next is yourself.
-
If you encode a single character into bytes using the UTF-8 encoding, it can result in more than a single byte. It wouldn't make sense to have a method that decodes a single byte, as that would only work on a very limited part of the character set. If you have a character that actually was encoded into a single byte, you just have to put that byte in an array to decode it. If you are trying to decode data byte by byte, that doesn't work, as some characters may need more than one byte of the data.
Despite everything, the person most likely to be fooling you next is yourself.
Guffa wrote:
If you have a character that actually was encoded into a single byte, you just have to put that byte in an array to decode it.
If you have a character that was encoded into a single byte using UTF8, then it was an ASCII character. Instead of allocating lots of small byte arrays, you can just do this:
char DecodeASCII(byte b)
{
if (b >= 128)
throw new ArgumentException("This is not a single-byte character");
else
return (char)b;
}