Table of Contents

ParseInt

int, int ParseInt(str s, int base)

This function returns multiple values

Description

Parses s as an integer in the specified base. If base is 0, base 10 is used by default and Number prefixes are enabled. Supports signs.

Returns status and parsed number. Status is one of the following:

For simple parsing use atoi.

Examples

ParseInt("123", 0);
r1 -> PARSENUMBER_SUCCESS
r2 -> 123

ParseInt("0", 0);
r1 = PARSENUMBER_SUCCESS
r2 -> 0

ParseInt("999999999999", 0)
r1 -> PARSENUMBER_OVERFLOW
r2 -> 2147483647

ParseInt("-99999999999", 0)
r1 -> PARSENUMBER_OVERFLOW
r2 -> -2147483647

ParseInt("not a number", 0)
r1 -> PARSENUMBER_BADFORMAT

ParseInt("1.3", 0) -> 0
r1 -> PARSENUMBER_BADFORMAT

ParseInt("0xff", 0) // Hexadecimal prefix
r1 -> PARSENUMBER_SUCCESS
r2 -> 255

ParseInt("ff", 16) // Parse in hexadecimal
r1 -> PARSENUMBER_SUCCESS
r2 -> 255

ParseInt("0xff", 16) // 0x causes syntax error
r1 -> PARSENUMBER_BADFORMAT

ParseInt