• Pure

    Returns an integer by parsing the string for a number.

    For values too big or too small, returns max/min integer respectively. For an empty string or text that doesn't start with a number, returns 0.

    Lua: For null raises an error.

    Examples (Lua):

    S2I("") == 0
    S2I("-123") == -123
    S2I("-99999999") == -2147483648
    S2I("99999999") == 2147483647
    S2I("123abc") == 123
    S2I("abc123") == 0
    S2I(nil) -- error

    Parameters

    • s: string

      The string to be converted.

    Returns number

    Note

    This function only works for decimal strings. Hexadecimal or octal strings are not supported.

    Note

    The parser stops at the first non-number character [0-9.]. If the input string starts with some valid input but ends in invalid input this will return the conversion of the valid part: S2I("123asd") == 123.

Generated using TypeDoc