This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| functions:parseint [2017/03/21 14:02] – created korshun | functions:parseint [2017/04/17 12:38] (current) – korshun | ||
|---|---|---|---|
| Line 6: | Line 6: | ||
| ===== Description ===== | ===== Description ===== | ||
| - | Parses s as an integer in the specified base. If base is 0, base 10 is used by default and prefixes | + | Parses s as an integer in the specified base. If base is 0, base 10 is used by default and [[: |
| - | Returns status and result. | + | Returns status and parsed number. Status is one of the following: |
| + | * PARSENUMBER_SUCCESS -- number successfully parsed. r2 contains the result. | ||
| + | * PARSENUMBER_OVERFLOW -- the number is too big to fit into a variable. r2 contains [[constants: | ||
| + | * PARSENUMBER_BADFORMAT -- the number failed to parse. r2 is unchanged. | ||
| - | See [[:Number parsing]] for features and examples. | + | <note tip>For simple parsing use [[atoi]].</ |
| + | |||
| + | ===== Examples ===== | ||
| + | < | ||
| + | ParseInt(" | ||
| + | r1 -> PARSENUMBER_SUCCESS | ||
| + | r2 -> 123 | ||
| + | |||
| + | ParseInt(" | ||
| + | r1 = PARSENUMBER_SUCCESS | ||
| + | r2 -> 0 | ||
| + | |||
| + | ParseInt(" | ||
| + | r1 -> PARSENUMBER_OVERFLOW | ||
| + | r2 -> 2147483647 | ||
| + | |||
| + | ParseInt(" | ||
| + | r1 -> PARSENUMBER_OVERFLOW | ||
| + | r2 -> -2147483647 | ||
| + | |||
| + | ParseInt(" | ||
| + | r1 -> PARSENUMBER_BADFORMAT | ||
| + | |||
| + | ParseInt(" | ||
| + | r1 -> PARSENUMBER_BADFORMAT | ||
| + | |||
| + | ParseInt(" | ||
| + | r1 -> PARSENUMBER_SUCCESS | ||
| + | r2 -> 255 | ||
| + | |||
| + | ParseInt(" | ||
| + | r1 -> PARSENUMBER_SUCCESS | ||
| + | r2 -> 255 | ||
| + | |||
| + | ParseInt(" | ||
| + | r1 -> PARSENUMBER_BADFORMAT | ||
| + | |||
| + | ParseInt | ||
| + | </ | ||