Category Archives: iOS

useful CFString snippets

		public static byte[] StringToCFString(string value) {
			byte[] b;

			b = new byte[value.Length + 10];
			b[4] = 0x8c;
			b[5] = 07;
			b[6] = 01;
			b[8] = (byte)value.Length;
			Encoding.ASCII.GetBytes(value, 0, value.Length, b, 9);
			return b;
		}

		public static byte[] StringToCString(string value) {
			byte[] bytes = new byte[value.Length + 1];
			Encoding.ASCII.GetBytes(value, 0, value.Length, bytes, 0);
			return bytes;
		}

		public static string CFStringToString(byte[] value) {
			return Encoding.ASCII.GetString(value, 9, value[9]);
		}