Instant methods: parse_uint64()

The instant method parse_uint64() converts the unsigned integral number stored in the string operand in the corresponding 64-bit unsigned uint64 value.

Declaration

Form 1:

uint64 string.parse_uint64( uint64 aDefault )

Form 2:

uint64 string.parse_uint64( uint64 aDefault, int32 aRadix )

Parameters

aDefault

Value to return if the string doesn't contain any valid number.

aRadix

Determines the format of the number stored in the string. This parameter can assume values 2, 8, 10 or 16. Accordingly the string content is considered as being a number with binary, octal, decimal or hexadecimal notation. When the passed value is other than 2, 8 or 16, the value 10 is assumed implicitly.

Discussion

The parse_uint64() method parses the string operand interpreting its content as an integral number. Eventual whitespace signs ' ' (space), '\t' (tabulator), '\n' (newline), '\v' (vertical tab), '\f' (form-feed) and '\r' (carriage return) lying at the begin of the string are ignored and skipped over.

Generally the method tries to parse as many signs as possible. If the end of the string or an unexpected sign is found, the method stops and returns the already read number as signed uint64 value. If the string content is invalid (the string doesn't contain any of the expected digit or letter signs), the value passed in the parameter aDefault is returned instead. For example:

var string s1 = "1369"; var string s2 = " 1251-other content"; var string s3 = "X251"; var uint64 r1 = s1.parse_uint64( 0 ); // r1 = 1369 // Skip over leading whitespace signs and ignore the signs // following the number 1251 var uint64 r2 = s2.parse_uint64( 0 ); // r2 = 1251 // The number doesn't start with an expected sign. Thereupon // return the default value. var uint64 r3 = s3.parse_uint64( 0 ); // r3 = 0

In its first form, the method interprets the string content as a number stored in decimal notation. With the second form, you can specify in the additional parameter aRadix the expected notation of the number. The parameter aRadix can assume values 2, 8, 10 or 16 identifying that the string contains a number in binary, octal, decimal or hexadecimal notation. For example:

var string s1 = "01110000"; var string s2 = "77610"; var string s3 = "A7f4"; // Parse number in binary notation var uint64 r1 = s1.parse_uint64( 0, 2 ); // r1 = 112 // Parse number in octal notation var uint64 r2 = s2.parse_uint64( 0, 8 ); // r2 = 32648 // Parse number in hexadecimal notation var uint64 r3 = s3.parse_uint64( 0, 16 ); // r3 = 42996