Str.asciiStringToUnsigned

A convenience function for converting a string to an unsigned number.

This function assumes that @str contains only a number of the given @base that is within inclusive bounds limited by @min and @max. If this is true, then the converted number is stored in @out_num. An empty string is not a valid input. A string with leading or trailing whitespace is also an invalid input.

@base can be between 2 and 36 inclusive. Hexadecimal numbers must not be prefixed with "0x" or "0X". Such a problem does not exist for octal numbers, since they were usually prefixed with a zero which does not change the value of the parsed number.

Parsing failures result in an error with the %G_NUMBER_PARSER_ERROR domain. If the input is invalid, the error code will be %G_NUMBER_PARSER_ERROR_INVALID. If the parsed number is out of bounds - %G_NUMBER_PARSER_ERROR_OUT_OF_BOUNDS.

See g_ascii_strtoull() if you have more complex needs such as parsing a string which starts with a number, but then has other characters.

struct Str
static
bool
asciiStringToUnsigned
(
string str
,
uint base
,
ulong min
,
ulong max
,
out ulong outNum
)

Parameters

str string

a string

base uint

base of a parsed number

min ulong

a lower bound (inclusive)

max ulong

an upper bound (inclusive)

outNum ulong

a return location for a number

Return Value

Type: bool

%TRUE if @str was a number, otherwise %FALSE.

Throws

GException on failure.

Meta

Since

2.54