comparison 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
comparison
equal deleted inserted replaced
29:e38192f55d2d 30:23fd4247fc1c
22 public static byte[] StringToBytes(string str) 22 public static byte[] StringToBytes(string str)
23 { 23 {
24 return utf8.GetBytes(str); 24 return utf8.GetBytes(str);
25 } 25 }
26 26
27 public static string ByteArrayToHexString(byte[] arr)
28 {
29 return ByteArrayToHexString(arr, true);
30 }
31
32 public static string ByteArrayToHexString(byte[] arr, bool spaceBytes)
33 {
34 StringBuilder sb = new StringBuilder(arr.Length);
35 string format = (spaceBytes ? "{0,-3:x2}" : "{0:x2}");
36
37 foreach (byte b in arr)
38 {
39 sb.Append(String.Format(format, b));
40 }
41
42 return sb.ToString().TrimEnd();
43 }
44
27 public static string RemoveFromLast(string stringToTrim, char removeFrom) 45 public static string RemoveFromLast(string stringToTrim, char removeFrom)
28 { 46 {
29 return stringToTrim.Substring(0, stringToTrim.LastIndexOf(removeFrom)); 47 return stringToTrim.Substring(0, stringToTrim.LastIndexOf(removeFrom));
30 } 48 }
31 49