parse


Description:

[ Version ( since = "2.12" ) ]
public static int64 parse (string str, uint _base = 0)

Converts a string to a gint64 value.

If the correct value would cause overflow, int64.MAX or int64.MIN is returned, and ERANGE is stored in errno. If the base is outside the valid range, zero is returned, and ERANGE is stored in errno. If the string conversion fails, zero is returned.

Example: String to int64:

public static int main (string[] args) {
// Output: ``12345``
print ("%" + int64.FORMAT + "\n", int64.parse ("12345"));

// Output: ``-12345``
print ("%" + int64.FORMAT + "\n", int64.parse ("-12345"));

// Output: ``0``
print ("%" + int64.FORMAT + "\n", int64.parse ("d12345"));

// Output: ``12345``
print ("%" + int64.FORMAT + "\n", int64.parse ("12345D"));
return 0;
}

valac --pkg glib-2.0 int64.parse.vala

Parameters:

str

the string to convert to a numeric value.

Returns:

the int64 value or zero on error.