Welcome to the Creatures Wiki! Log in and join the community.

STOI

From Creatures Wiki
Jump to navigation Jump to search

STOI is a CAOS command which converts between strings and integers.

Usage[edit]

Syntax: STOI str (string)

Returns the integer made from converting str. str is in the format [whitespace][+|-][nn] where [nn] may be any length. In the event of an error 0 is returned.

If str corresponds to something outside the integer range (which is <math>-2^{31} \le n < 2^{31}</math>) the numbers wrap, so STOI "21474835648" == -2147483648. Note that this behaviour is different to the CEE's when such numbers are found in injected code.

If a string of the above format begins str but something is attached to the end, the string is truncated at the end of the well-formatted portion. Note that this means a string representing a float will be truncated instead of rounded. (Hence, STOI VTOS va00 is a roundabout way to get floor(va00).)

This command is exactly equivalent to C's atoi() function.

Examples[edit]

OUTV STOI "123"
    123
OUTV STOI "    1234"
    1234
OUTV STOI "1234.5"
    1234
OUTV STOI "  123456, I say!"
    123456
OUTV STOI "Hello!"
    0

See also[edit]