StringToHex()

Converts each character in a string to its hexadecimal equivalent.

Availability 

Marketing Cloud Engagement ✅ Yes
Marketing Cloud Next ❌ No

Syntax 

1StringToHex(sourceString, charSet)

The StringToHex() function has two parameters:

  • sourceString (string): Required. The string to convert to hexadecimal character codes.
  • charSet (string): The character set to use for encoding. Accepted values: UTF-8 or UTF-16. The default value is UTF-8. You can also specify UTC-16.

Usage 

To use the function, pass it a string to encode. You can optionally specify UTF-16 encoding.

1%%[
2  Var @sourceString, @hexStringUtf8, @hexStringUtf16
3  Set @sourceString = "Hello world!"
4  Set @hexStringUtf8 = StringToHex(@sourceString)
5  Set @hexStringUtf16 = StringToHex(@sourceString, 'UTF-16')
6]%%
7<p>Source string: %%=v(@sourceString)=%%</p>
8<p>UTF-8 hex string: %%=v(@hexStringUtf8)=%%</p>
9<p>UTF-16 hex string: %%=v(@hexStringUtf16)=%%</p>

The example returns the source string, the UTF-8 hex string, and the UTF-16 hex string.

1Source string: Hello world!
2UTF-8 hex string: 48656c6c6f20776f726c6421
3UTF-16 hex string: 480065006c006c006f00200077006f0072006c0064002100