Mercurial > repos > IBBoard
diff Lang/StringManipulation.cs @ 30:23fd4247fc1c
* Add "big-endian" binary reader that reads ints/shorts in big-endian format
* Add methods to String Manipulation to output a byte string as hex characters
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 19 Apr 2009 11:31:47 +0000 |
parents | 0352fa33ee8f |
children | cc7fae81afec |
line wrap: on
line diff
--- a/Lang/StringManipulation.cs Sat Apr 11 14:47:20 2009 +0000 +++ b/Lang/StringManipulation.cs Sun Apr 19 11:31:47 2009 +0000 @@ -22,6 +22,24 @@ public static byte[] StringToBytes(string str) { return utf8.GetBytes(str); + } + + public static string ByteArrayToHexString(byte[] arr) + { + return ByteArrayToHexString(arr, true); + } + + public static string ByteArrayToHexString(byte[] arr, bool spaceBytes) + { + StringBuilder sb = new StringBuilder(arr.Length); + string format = (spaceBytes ? "{0,-3:x2}" : "{0:x2}"); + + foreach (byte b in arr) + { + sb.Append(String.Format(format, b)); + } + + return sb.ToString().TrimEnd(); } public static string RemoveFromLast(string stringToTrim, char removeFrom)