1 The `ord()` function extracts the byte value of the character within the 2 given input string at the given offset. 3 4 If the offset argument is omitted, the byte value of the first character 5 is returned. 6 7 Returns `null` if the given input string argument is not a string. 8 9 Returns `null` if the given input string is empty. 10 11 Returns `null` if the given offset value is invalid. 12 13 Invalid offsets are non-integer values or integers equal to or larger than 14 the length of the input string. Negative offsets are converted to positive 15 ones by adding the length of the input string. If the negative value is 16 too large, the offset is considered invalid. 17 18 19 -- Testcase -- 20 {% 21 print(join("\n", [ 22 ord(123), 23 ord(""), 24 ord("abcd", "inval"), 25 ord("abcd"), 26 ord("abcd", 0), 27 ord("abcd", 1), 28 ord("abcd", -1), 29 ord("abcd", 10), 30 ord("abcd", -10) 31 ]), "\n"); 32 %} 33 -- End -- 34 35 -- Expect stdout -- 36 null 37 null 38 null 39 97 40 97 41 98 42 100 43 null 44 null 45 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt