Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Pascal

Idiom #304 Encode string into UTF-8 bytes

Create the array of bytes data by encoding the string s in UTF-8.

var
  data: pbyte absolute s;

Declare data as a variable that points to the same absolute address as the string s.
The type pbyte (pointer to a byte) can be accessed as an array, so data[0] is the first byte of the string.
using System.Text;
byte[] data = Encoding.UTF8.GetBytes(s);

New implementation...