[Edit]
+
0
-
0

C# string to byte array

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
string text = "£100"; // encoding (string to bytes conversion) byte[] data = Encoding.ASCII.GetBytes(text); // test string product = Encoding.ASCII.GetString(data); string status = (text == product ? "CORRECT" : "INCORRECT"); Console.WriteLine($"{"BEFORE",-10} {"AFTER",-10} {"STATUS",-10}"); Console.WriteLine($"{text, -10} {product, -10} {status, -10}"); Console.WriteLine(); // bytes Console.Write("Bytes: "); foreach (byte entry in data) Console.Write(entry + " "); Console.WriteLine(); /* Output: BEFORE AFTER STATUS £100 ?100 INCORRECT Bytes: 63 49 48 48 */