parse


Description:

public static long parse (string str, uint _base = 0)

Interprets an integer value in a byte string pointed to by str.

Function discards any whitespace characters until first non-whitespace character is found. Then it takes as many characters as possible to form a valid integer number representation and converts them to integer value. The valid integer value consists of the following parts:

  • (optional) plus or minus sign
  • numeric digits

Example: String to long:

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

// Output: ``-12345``
print ("%ld\n", long.parse ("-12345"));

// Output: ``0``
print ("%ld\n", long.parse ("d12345"));

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

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

Parameters:

str

pointer to the null-terminated byte string to be interpreted

Returns:

Integer value corresponding to the contents of str on success. If the converted value falls out of range of corresponding return type, the return value is undefined. If no conversion can be performed, ​0 is returned.