Partilhar via


MSPL Types and Type Conversion

MSPL Types and Type Conversion

All variables in MSPL are implicitly declared; you cannot explicitly declare a variable as any of the types listed below. These assignments must be of the form:

variableName = value;

Floating-point and integer values must be specified using the en-US cultural format.

MSPL Data Types

The following data types are supported by MSPL:

  • string: a Unicode string value.

  • integer: a 32-bit signed integer value.

  • float: an IEEE single-precision floating point value.

  • bool: a value that evaluates to true or false.

  • [ ]: a flat file.

  • collection: a grouping of one or more of the previous types.

Type Conversion Rules

If a variable has been implicitly declared as one type through assignment, and a value of a different type is later assigned to it, the type will be coerced by the type conversion rules below.

If the source type is string:

  • Result type is integer: The string will be converted to the corresponding integer value. An error occurs if the source string cannot be entirely consumed.

  • Result type is float: The string will be converted to a floating-point value. An error occurs if the source string cannot be entirely consumed.

  • Result type is bool: true if the string has a nonzero length; false if it is zero characters in length.

  • Result type is collection: A collection that contains a single string is created.

If the source type is integer:

  • Result type is string: A string representation of the integer value is created.

  • Result type is float: The integer will be converted to a floating-point value.

  • Result type is bool: true if the integer is nonzero; false if it is zero.

  • Result type is collection: A collection that contains a single integer value is created.

If the source type is float:

  • Result type is string: A string representation of the float value is created.

  • Result type is integer: An integer representation of the float value is created. All digits after the decimal point are truncated.

  • Result type is bool: true if the float is nonzero; false if it is zero.

  • Result type is collection: A collection that contains a single float value is created.

If the source type is bool:

  • Result type is string: If the value is true, a string that contains "true" is created; else if false, a string that contains "false" is created.

  • Result type is integer: If the value is true, an integer with a value of 1 is created; else if false, an integer with a value of 0 is created.

  • Result type is float: If the value is true, a float with a value of 1.0 is created; else if false, a float with a value of 0.0 is created.

  • Result type is collection: A collection that contains a single bool value is created.

If the source type is collection:

  • Result type is string: If at least one element is present in the collection, the coercion rules for converting the base type to a string are applied to the first element; else, if the collection is empty, an empty string value is used.

  • Result type is integer: If at least one element is present in the collection, the coercion rules for converting the base type to an integer are applied to the first element; else, if the collection is empty, the value 0 is used.

  • Result type is float: If at least one element is present in the collection, the coercion rules for converting the base type to a float are applied to the first element; else, if the collection is empty, the value 0.0 is used.

  • Result type is bool: true if the collection contains one or more items; false if it is empty.

    Note

    Two collections cannot be compared. The script will abort with an error if a collection comparison is attempted.