{ord:string}

Description

Returns the byte value of the first character of the given string, as a decimal number. It is the AA counterpart of the PHP ord function. The result is a single byte (0 to 255), not a Unicode code point: for a multi-byte UTF-8 character such as an a-acute the value is the first byte (195), not the code point 225. Only the first character is read; any further characters are ignored. An empty string returns 0. One trap on this engine: a sole argument of exactly the single character 0 is treated by the parser as no argument at all, so it also returns 0 rather than 48 - feed 00 or prefix the value if you need the real code of the digit zero. The inverse direction (a code back to a character) has no template command. Parameters are not trimmed, so a leading space is read as the space character (code 32).

Parameters

string required

The text to inspect. Only its first character is used; the rest is ignored. Not trimmed, so a leading space counts as the space character. An empty string gives 0, and the single character 0 on its own also gives 0 (a parser quirk).

Examples

test{ord: x}
Expected32
Actual32
Parameters are not trimmed for this command, so a leading space is read as the actual first character. The space character is 32.
test{ord:A}
Expected65
Actual65
The most basic use: the byte value of a single character. Capital A is 65 in ASCII.
test{ord:z}
Expected122
Actual122
Lowercase letters sit higher in the table than capitals; lowercase z is 122.
test{ord:7}
Expected55
Actual55
Digits other than 0 are not affected by the parser quirk. The character 7 is 55 in ASCII.
test{ord:}
Expected0
Actual0
With no character to read, the result is 0. This is the clean empty case.
test{ord:Apple}
Expected65
Actual65
Any characters after the first are ignored, so this is the code of A, the same as ord of A alone.
test{ord:0}
Expected0
Actual0
The code of the character 0 should be 48, but the template parser treats a sole argument that is exactly the single character 0 as no argument at all (PHP empty), so expand runs on an empty string and returns 0. This is a parser quirk, not what ord itself does.
test{ord:00}
Expected48
Actual48
To get the real code of the digit zero, give the parser something that is not falsy. Two zeros (or any string starting with zero) is read normally; only the first character is used, so 00 yields 48, the true code of 0.