parse_int
fn parse_int(string s) -> Result<int, string> Import
Source: use conv::{parse_int}; src/conv.hy Parses a decimal integer, such as "42", " -7 " or "+3".
Parameters#
| Name | Type |
|---|---|
s | string |
Returns#
Result<int, string>
Errors#
Err("invalid integer") when s is empty or has a character that is not a
digit. See parse_int_radix for the overflow caveat.
Examples#
use conv::{parse_int};
use tests::assert;
assert!((parse_int(" 42 ") ?? 0) == 42);
let bad = match parse_int("4x2") {
Result::Err(e) => e,
Result::Ok(_) => "",
};
assert!(bad == "invalid integer");
See also#
conv::parse_int_radixint_to_dec: Formatsnin decimal; the same asformat("%i", n).int_to_hex: Formatsnin lowercase hexadecimal without a prefix; a negativengets a leading-.int_to_bin: Formatsnin binary without a prefix; a negativengets a leading-.parse_float: Parses a decimal float such as"3.5","-0.25","1e3"or"42".