J
Jamie Risk
This is the code snippet that I've come up to convert a byte[]
to string. Is there a best practiced method for such a conversion?
- Jamie
public static string ByteArrayToString(byte[] array)
{
if (null == array || 0 == array.Length)
{
throw new NullReferenceException();
return null;
}
else
{
Encoding ascii = Encoding.ASCII;
char[] asciiChars =
new char[ascii.GetCharCount(array, 0, array.Length)];
string str = null;
ascii.GetChars(array, 0, array.Length, asciiChars, 0);
foreach (string s in (new string(asciiChars)).Split('\n'))
{
if (str != null) str += Environment.NewLine;
str += s.Trim();
}
return str;
}
}
to string. Is there a best practiced method for such a conversion?
- Jamie
public static string ByteArrayToString(byte[] array)
{
if (null == array || 0 == array.Length)
{
throw new NullReferenceException();
return null;
}
else
{
Encoding ascii = Encoding.ASCII;
char[] asciiChars =
new char[ascii.GetCharCount(array, 0, array.Length)];
string str = null;
ascii.GetChars(array, 0, array.Length, asciiChars, 0);
foreach (string s in (new string(asciiChars)).Split('\n'))
{
if (str != null) str += Environment.NewLine;
str += s.Trim();
}
return str;
}
}