Files
libremetaverse/libsecondlife-cs/Utils/Utils.cs
Michael Cortez 7f9d2de5f6 The mallet gets bigger' en' bigger...
git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@158 52acb1d6-8a22-11de-b505-999d5b087335
2006-08-14 20:05:22 +00:00

82 lines
1.5 KiB
C#

using System;
namespace libsecondlife.Utils
{
/// <summary>
/// Summary description for Utils.
/// </summary>
public class ByteArrayStuff
{
private ByteArrayStuff()
{
// This class isn't intended to be instantiated
}
public static string ByteArrayToString( byte[] byteArray )
{
if ( byteArray == null )
{
return "";
}
string output = "";
bool printable = true;
for (int i = 0; i < byteArray.Length; ++i)
{
// Check if there are any unprintable characters in the array
if ((byteArray[i] < 0x20 || byteArray[i] > 0x7E) && byteArray[i] != 0x09
&& byteArray[i] != 0x0D)
{
printable = false;
}
}
if (printable)
{
output = Helpers.FieldToString(byteArray);
}
else
{
for (int i = 0; i < byteArray.Length; i += 16)
{
for (int j = 0; j < 16; j++)
{
if ((i + j) < byteArray.Length)
{
string s = String.Format("{0:X} ", byteArray[i + j]);
if( s.Length == 2 )
{
s = "0" + s;
}
output += s;
}
else
{
output += " ";
}
}
for (int j = 0; j < 16 && (i + j) < byteArray.Length; j++)
{
if (byteArray[i + j] >= 0x20 && byteArray[i + j] < 0x7E)
{
output += (char)byteArray[i + j];
}
else
{
output += ".";
}
}
output += "\n";
}
}
return output;
}
}
}