Documentation/Calc Functions/CODE

    From The Document Foundation Wiki
    Other languages:


    Function name:

    CODE

    Category:

    Text

    Summary:

    Determines the code point in the current coded character set that corresponds to the first character of a given text string or number.

    The CODE function is complementary to the CHAR function.

    For some characters, CODE may return the same code point as the UNICODE function but for other characters the code point returned may be system-specific and different.

    Syntax:

    CODE(Text)

    Returns:

    Returns an integer in the range 0 ≤ n ≤ 255, which is the code point in the current coded character set that corresponds to the first character of the given text string or number.

    Arguments:

    Text is a text string (in quotation marks) or a number, or a reference to a cell containing such a string or number, the first character of which is the character whose code point is to be determined.

    • Text can be an empty string, in which case CODE returns the value 0.
    • If the first character of Text does not correspond to one of the 256 code points in the current coded character set, then CODE returns the value 63 (which is the ASCII code for a question mark).
    • If Text is a non-negative number, then CODE returns the code point corresponding to the first digit of that number. If Text is a negative number, then CODE returns the code point corresponding to the minus sign (which has an ASCII code of 45).

    Additional details:

    For any code point n, n = CODE(CHAR(n))

    Since the code points returned for some characters can differ between systems, spreadsheets using the CODE function may not be portable.

    Examples:

    Formula Description Returns
    =CODE("Hieronymus") Here the function returns the value 72, which is the code point for uppercase "H". 72
    =CODE("hieroglyphic") Here the function returns the value 104, which is the code point for lowercase "h". 104
    =CODE(D1) where cell D1 contains a semicolon (";") character. Here the function returns the value 59, which is the code point for the semicolon. 59
    =CODE(−345.678) Here the function returns the value 45, which is the code point for the minus sign. 45
    =CODE(23.4) Here the function returns the value 50, which is the code point for the digit "2". 50

    Related LibreOffice functions:

    CHAR

    UNICHAR

    UNICODE

    ODF standard:

    Section 6.20.5, part 2

    Related (or similar) Excel functions:

    CODE