Handlebars Helper Function: stringToHex

Converts each character in a string to its hexadecimal equivalent.

This helper is available in the Winter ’27 release of Marketing Cloud Next.

ParameterTypeDescription
sourceStringStringRequired. The string to convert.
charSetStringThe character set to use. Specify as a named parameter with a value of UTF-8 or UTF-16. The default is UTF-8.

The function returns a hexadecimal string that represents the encoded characters in sourceString.

This example converts a string of text to its UTF-8 hexadecimal representation.

The function returns:

This example converts the same string, but specifies UTF-16 encoding. Each character requires more bytes in UTF-16, so the resulting string is longer.

The function returns: