parse
Description:
Converts a string to a uint64 value.
This function behaves like the standard strtoull
function does in the C locale. It does this without actually changing the current
locale, since that would not be thread-safe.
This function is typically used when reading configuration files or other non-user input that should be locale independent. To handle input
from the user you should normally use the locale-sensitive system strtoull
function.
If the correct value would cause overflow, int64.MAX is returned, and ERANGE is stored in GLib.errno. If the base is outside the valid range, zero is returned, and EINVAL is stored in errno. If the string conversion fails, zero is returned.
Example: String to uint64:
public static int main (string[] args) {
// Output: ``12345``
print ("%" + uint64.FORMAT + "\n", uint64.parse ("12345"));
// Output: ``18446744073709539271``
print ("%" + uint64.FORMAT + "\n", uint64.parse ("-12345"));
// Output: ``0``
print ("%" + uint64.FORMAT + "\n", uint64.parse ("d12345"));
// Output: ``12345``
print ("%" + uint64.FORMAT + "\n", uint64.parse ("12345D"));
return 0;
}
valac --pkg glib-2.0 uint64.parse.vala
Parameters:
str |
the string to convert to a numeric value. |
Returns:
the guint64 value or zero on error. |