Cast a string (where possible) to a primitive type.