SDU
Personal tools

Data Type Conversion

From SDU

Jump to: navigation, search
To make corrections or additions to this article, select the edit tab above.
To discuss or ask questions about this article, select the discussion tab above.

Overview

This This article details how to convert from one data type to another in Spel code. This concept is regarded as casting.

Details

Primary data types used in USD spell.

  • string
  • int
  • float
  • date
  • duration
  • bool
  • uuid (introduced in r11.x)
  • object

Example:

string MyString;
int MyInt;
float MyFloat;
date MyDate;
duration MyDuration;
uuid MyUUID;
 
MyString = "Hello world no: " +(string) 1; // result: "Hello world no: 1"
MyInt = (int) "2 times");  // result: 2
MyFloat = (float)MyInt; // result: 2.00000
MyDate = (date)( (string) now()); // result: the actual date depending of your system time configuration
MyDuration = (duration)((int) "2" + 3), // result: duration of 5 sec.
MyUUID = (uuid)expand( "&{'mylogin'=cnt.userid->id}"); // result: the id of contact having userid "mylogin"

Arrays

In Spell code you can use arrays as well.

Accessing array fields is very similar to other languages, simply use

myArray[3]

to access forth element of an array myArray. Arrays are 0-based.

Here is the example of declarantion of a new array of strings with 4 elements:

string msgs[4];
This page was last modified 13:17, 16 May 2011.  This page has been accessed 2,283 times.  Content is available under Attribution-Noncommercial-Share Alike 3.0 UnportedDisclaimers