From 39afe44d16e8406c46125e49933301b1faae55f7 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 5 Sep 2014 18:54:48 +0100 Subject: [PATCH] Change Console output to String output. Add function to write String output to Console. --- DiscImageChef/PrintHex.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/DiscImageChef/PrintHex.cs b/DiscImageChef/PrintHex.cs index fe98946a..a9564e2f 100644 --- a/DiscImageChef/PrintHex.cs +++ b/DiscImageChef/PrintHex.cs @@ -43,14 +43,21 @@ namespace DiscImageChef { 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 subcounter = 0; for (long i = 0; i < array.LongLength; i++) { if (counter == 0) { - Console.WriteLine(); - Console.Write("{0:X16} ", i); + sb.AppendLine(); + sb.AppendFormat("{0:X16} ", i); } else { @@ -66,7 +73,7 @@ namespace DiscImageChef } } - Console.Write("{0:X2}", array[i]); + sb.AppendFormat("{0:X2}", array[i]); if (counter == width - 1) { @@ -76,8 +83,10 @@ namespace DiscImageChef else counter++; } - Console.WriteLine(); - Console.WriteLine(); + sb.AppendLine(); + sb.AppendLine(); + + return sb.ToString(); } } }