Change Console output to String output.

Add function to write String output to Console.
This commit is contained in:
2014-09-05 18:54:48 +01:00
parent ebfd36991b
commit 39afe44d16

View File

@@ -43,14 +43,21 @@ namespace DiscImageChef
{ {
public static void PrintHexArray(byte[] array, int width) public static void PrintHexArray(byte[] array, int width)
{ {
Console.WriteLine(ByteArrayToHexArrayString(array, width));
}
public static string ByteArrayToHexArrayString(byte[] array, int width)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
int counter = 0; int counter = 0;
int subcounter = 0; int subcounter = 0;
for (long i = 0; i < array.LongLength; i++) for (long i = 0; i < array.LongLength; i++)
{ {
if (counter == 0) if (counter == 0)
{ {
Console.WriteLine(); sb.AppendLine();
Console.Write("{0:X16} ", i); sb.AppendFormat("{0:X16} ", i);
} }
else else
{ {
@@ -66,7 +73,7 @@ namespace DiscImageChef
} }
} }
Console.Write("{0:X2}", array[i]); sb.AppendFormat("{0:X2}", array[i]);
if (counter == width - 1) if (counter == width - 1)
{ {
@@ -76,8 +83,10 @@ namespace DiscImageChef
else else
counter++; counter++;
} }
Console.WriteLine(); sb.AppendLine();
Console.WriteLine(); sb.AppendLine();
return sb.ToString();
} }
} }
} }