Simple positive number
Input
str_to_int('42')
Output
42
The string '42' converts to the integer 42.
Full lesson preview
Convert a numeric string into an integer, handling optional whitespace and sign characters.
Problem statement
Task
Examples
Input
str_to_int('42')
Output
42
The string '42' converts to the integer 42.
Input
str_to_int(' -7 ')
Output
-7
Leading/trailing whitespace is ignored and the sign is preserved.
Input format
Output format
Constraints
Samples
Input
str_to_int('0')
Output
0
The string '0' converts to integer 0.