EncodeBase16 (open)

Encodes a string into a hexadecimal string.

Syntax

// Core function, no LOADLIB necessary

STRING FUNCTION EncodeBase16(STRING text)

Parameters

STRING text

String to encode

Return value

STRING

The encoded string

Description

Certain characters have special significance or can cause dangerous side-effects when used in certain situations, and may need to be avoided. Examples of such situations are (back)slashes when creating filenames, or linefeeds when creating JavaScript variable names.

If no other encoding function will suffice or is safe enough, you can convert a string to hexadecimal codes. Base 16 encoding only uses the characters 0-9 and A-F, which will be safe for almost any application. Another advantage of base 16 encoding is the predictable size of the output string. EncodeBase16 guarantees that the length of its result will be exactly twice the length of the original string. For other encoding functions, the length of their results varies depending on both the input string contents, and the input string length.

Examples

// returns "48656C6C6F2C20576F726C64"
STRING example1 := EncodeBase16("Hello, World");

// returns "313233"
STRING example2 := EncodeBase16("123");