code

Prev Next

Function Names

code

Description

This function returns the UNICODE character code of the character supplied.

Vectorization: This function supports vectorization in the 1st function parameter. Instead of providing a single value, you can provide a set or even a nested set which contain multiple values. The function will then process every value and its return value contains a corresponding set containing all results.

Call as: function

Restrictions

Indirect parameter passing is disabled
Vectorization is allowed in the 1st function parameter

Parameter count

1-2

Parameters

No.TypeDescription
1
input
string
set
input string

Input string containing character to decode, or in case of vectorization: Set ctontaining characters

Opt. 2
input
numeral character position

Character position, if a character other than the 1st character needs to be decoded. Negative indexing: Negative values count from right to left, e.g. -1 = last character.

Default value: 0

Return value

TypeDescription
numeral
set
character code

>0: UNICODE character code
0: Empty string
-1: Attempted to decode character at positition outside the string If vectorization is applied, then a set containing the results is returned.

Examples

               echo( code( 'Café 4.0 €' ) ); // C
               echo( code( 'Café 4.0 €', 3 ) ); // é
               echo( code( 'Café 4.0 €', -1 ) ); // €
               echo( code( 'Café 4.0 €', 99 ) ); // -1 (out of bounds)
               echo( code( '𝄞' ) ); // Violin clef
               echo( code( '' ) ); // 0 returned
               echo( code( characters(Café) ) ); // Vectorization example

Output

67
233
8364
-1
119070
0
{67,97,102,233}
Try it yourself: Open LIB_Function_code.b4p in B4P_Examples.zip. Decompress before use.

See also

chr