Next: atoi, Previous: stoca, Up: Conversion Functions [Contents][Index]
strtoi
The standard function strtoi
provides the following interface:
type Strtoi_Result = struct { uint<64> off; int<64> val; }; fun strtoi = (string str, int base = 10, ulong start = 0) Stroi_Result: { … }
It parses a signed integral number in the given base in the
string str at position start and returns its value and its
length in the val and off fields of a new
Strtoi_Result
instance.
Specifying a start that is greater than or equal to the length
of the string causes a E_out_of_bound
exception to be raised.
The accepted values for base are 2
, 8
, 10
(the default) and 16
. If any other base is requested an
E_inval
exception is raised.
Note that this function parses an integer but permits more characters to follow the given integer. As an example, take a look at parsing “12foo” in base 16:
#!!# strtoi ("12foo", 16) Strtoi_Result { off=3UL, val=303L } #!!# strtoi ("12foo", 16, 1) Strtoi_Result { off=3UL, val=47L }