Navigation

Data Types in DI#

The DI# language implements several methods allowing for easy manipulation of the basic data types (string, int, etc.).

In DI#, every manipulated value has a data type which determines: 

  • the possible operations
  • the available methods
  • how the value can be displayed or compared

Understanding data types helps avoid common errors and write more robust and maintainable DI# code.

DeclarationType
stringCharacter string
intInteger number
decimalDecimal number
datetimeDate et time
boolBoolean
timespanTime span
datasourceData source

In order to be compatible with projects or relational tables that include nullable fields, some of the data types allow for null values. However, we strongly advise against using nullable types in your code, in order to reduce the risks of execution error. 

Note: For certain data types (int, decimal, datetime) the DI# language allows values larger than what is supported by the database, meaning that it's possible to create a variable containing a value that cannot be stored in a database field of the same type as the variable. Refer to the projects and relational tables documentation to make sure of what the database limits are. 

// Examples for each type  
string a = "text";
int b = 1;
decimal c = 1.234;
datetime d1 = 2016.01.01 12:34:56;
datetime d2 = 2016.01.01;
bool e = true; // or false or null
timespan g = 2.25; // 2 days 6 hours
datasource h = {1, 2, 3};

Text (string)

A Unicode character string, each character is stored using 2 bytes. The string is delimited by quoting marks (").
Inside a string the symbol \ is used to escape when using special characters such as (\r) for carriage returns or (\n) for line breaks.

string
Property or methodReturned TypeDescription
LengthintReturns the number of characters in a string object. 
Capitalize(...)stringMyText.Capitalize() puts the 1st letter of the string in uppercase. MyText.Capitalize(true) puts the 1st letter of every word of the string in uppercase.
IndexOf(...)intMyText.IndexOf("find") returns the position of the 1st occurrence of the string passed as a parameter within the searched string.
LastIndexOf(...)intMyText.LastIndexOf("find") returns the position of the last occurrence of the string passed as a parameter within the searched string. 
Left(n)stringReturns the first n characters from the left of the string. Equivalent to MyText.Substring(0,n). 
Right(n)stringReturns the first n characters from the right of the string. Equivalent to MyText.Substring(MyText.Length-n,n).
Replace(...)stringMyText.Replace("find","replace") returns a new string object where all occurrences of the 1st parameter string have been replaced with the 2nd parameter string. 
Substring(...)stringMyText.Substring(start, length) Extracts part of the original string, starting at the 1st parameter index, for the number of characters specified in the 2nd parameter. MyText.Substring(start) Extracts the characters from the original string, starting at a specific position, to the end of the string. 
ToString(...)stringConverts all characters from a string to lowercase. 
ToLower()stringConverts all characters from a string to lowercase.
ToUpper()stringConverts all characters from a string to uppercase. 
Trim()stringRemoves all leading and trailing spaces from the string. 
// Examples
[[
string MyText = "this IS a character string ";
MyText.Length; // Returns the number 28
MyText.Capitalize (true); // Returns "This IS A Character String "
MyText.Capitalize(); // or MyText.Capitalize(false); // Return the string: "This IS a character string "
MyText.IndexOf("s"); // Returns the number 3
MyText.LastIndexOf("s"); // Returns the number 20
MyText.Left(12); // Returns the string: "This IS a ch"
MyText.Right(12); // Returns the string: "cter string "
MyText.Replace("character", "test");
// Returns the string: "this IS a test string "
MyText.Substring(12); // Returns "aracter string "
MyText.Substring(12, 3); // Returns "ara"
MyText.ToLower();
// Returns "this is a character string "
MyText.ToUpper();
// Returns the "THIS IS A CHARACTER STRING "
MyText.Trim(); // Return "This IS a character string"
]]

Note that based on the data type of the value returned by these methods and properties, you can chain other methods and properties. 

[[  
string MyTexte = "this is a CHARACTER string ";
MonTexte.Trim() .Replace ("CHARACTER", "test") .Capitalize(); // Returns "this is a CHARACTER string"
]]

Integer (int)

A 32 bits integer number between -2 147 483 648 and 2 147 483 647.

int
Property or MethodReturned TypeDescription
ToString()stringReturns the value of the object as a character string. 

Decimal Number (decimal)

High precision floating point numbers (28-29 significant digits). Values range from (-7.9x1028)/(10028) to (7.9x1028)/(10028). 

decimal
Property or MethodReturned TypeDescription
ToString()stringReturns the value of the object as a character string.

Date and Time (datetime)

Specifies a date with the following formats:

• aaaa.MM.jj HH:mm:ss

• aaaa.MM.jj HH:mm

• aaaa.MM.jj

Note that it is not a string: a date must not be inside quotes. For the the time, it can be omited. The seconds can be omited too. If you don't specify the secondes, the value will be 0 seconds.

datetime
Property or MethodReturned TypeDescription
AddYears(n)DateTimeAdds n years to the original date.
AddMonths(n)DateTimeAdds n months to the original date. 
AddDays(n)DateTime Adds n days to the original date.  
AddHours(n)DateTime Adds n hours to the original date.  
AddMinutes(n)DateTime Adds n minutes to the original date.  
AddSeconds(n)DateTimeAdds n seconds to the original date. 
DateDiff(d)TimeSpanSubtracts the d date from the original date and returns a timespan. 
isDST()boolReturns true if the original date is using Daylight Savings Time, based on the culture of the execution context. 
ToString(...)StringReturns the value of the object as a character string. The result can be formatted using customization parameters. For more details:  https://msdn.microsoft.com/fr-fr/library/az4se3k1(v=vs.110).aspx
DateDateTimeReturns a new date composed only of the year/month/day of the original date. Hours/minutes/seconds are ignored. 
YearIntReturns the year part of the original date. 
Month IntReturns the month number (1 to 12) of the original date. 
DayIntReturns the day of the month (1 to 31) of the original date. 
DayOfYearIntReturns the day of the year (1 to 365) of the original date. 
DayOfWeekIntReturns the day of the week (Sunday = 1, Saturday = 7) of the original date. 
HourIntReturns the hour part (0 to 23) of the original date. 
MinuteIntReturns the minute part (0 to 59) of the original date. 
SecondIntReturns the second part (0 to 59) of the original date. 
TicksIntReturns the number of ticks elapsed between January 1st, 0001 and the original date. 1 second = 10 000 000 ticks. 
[[  
datetime MyDate = 2016.01.01 12:34:56;
MyDate.AddYears (3); // Returns 2019-01-01 12:34:56
MyDate.AddMonths (3); // Returns 2016-04-01 12:34:56
MyDate.AddDays (3); // Returns 2016-01-04 12:34:56
MyDate.AddHours (3); // Returns 2016-01-01 15:34:56
MyDate.AddMinutes (3); // Returns 2016-01-01 12:37:56
MyDate.AddSeconds (3); // Returns 2016-01-01 12:34:59
MyDate.DateDiff ("2014.03.03").Days; // Returns 669
MyDate.isDST (); // Returns False
MyDate.ToString (); // Returns 2016.01.01 12:34:56
MyDate.ToString ("d/M/yyyy HH:mm:ss"); // Returns "1-1-2016 12:34:56"
MyDate.ToString ("F"); // Returns "1 January 2016 12:34:56"
MyDate.ToString ("ddd, dd MMM yyyy HH':'mm':'ss 'GMT' ");
// Returns "Friday., 1 January. 2016 12:34:56 GMT"
MyDate.Date; // Returns 2016-01-01 00:00:00
MyDate.Day; // Returnn 1
MyDate.DayOfWeek; // Returns 5
MyDate.DayOfYear; // Returns 1
MyDate.Hour; // Returns 12
MyDate.Minute; // Returns 34
MyDate.Month; // Returns 1
MyDate.Second; // Returns 56
MyDate.Ticks; // Returns 635872484960000000
MyDate.Year; // Returns 2016
]]

Boolean (bool)

A boolean value can be either TRUE or FALSE.

bool
Property or MethodReturned TypeDescription
ToString()stringReturns the character string "True" or "False". 

Date and Time (timespan)

Contrary to some other languages, timespan, in DI#, represents an amount of time, whether it's days, hours, minutes or seconds. This type exists primarily to perform operations datetime variables. Example: timespan t = date1 – date2 ; 

Note: To directly assign a timespan variable, you must specify a value corresponding to a number of days (for example, 2.25 if you want to represent 2 days and 6 hours) 

timespan
Property or MethodReturned TypeDescription
ToString()stringReturns the value of the object as a character string. 

Data Source (datasource)

Any type of data listed in this grid, or any complex data type like arrays, lists, dictionaries, etc. (similar to the var data type in C#.

A DI# array is a container for one or more variables, associating keys with values in an ordered way. It can be used for simple lists, dictionaries, or more complex purposes like hash tables, queues and more. The value of an array element can be a single variable, a list or a multidimensional array. The data type of each element in an array can be fixed or dynamic (the same way List<datatype> works in any .NET language).

Declaration of an array

A typical array declaration in DI# looks like this:
{ value1, value2, value3 }

datasource myArray = { 1, 2, 3, "abc", "def" };

You can define a collection of named elements like this:
{ fieldName1 : value1, fieldName2 : value2, fieldName3 : value3 }

datasource myDictionary = { FristName : "John", LastName : "Smith", Age : 30 };
// An element's value is an expression, which itself can contain other expressions like in
 this example
datasource myArray =
{
{ FirstName : "Jean", LastName : "Tremblay", Age : 40 },
{ FirstName : "John", LastName : "Smith", Age : 30 }
};
Instantiation of an array

There are 2 ways to instantiate an array:

  1. Declare an array with fixed length: int a[10];
  2. Declare an array with a variable length: string b[] ;
string a[] = {"text1", "text2", "text3"};  
int b[] = {1, 2, 3};
decimal c[] = {1.111, 2.222, 3.333};
datetime d[] = {2016.01.01 01:01:01, 2016.02.02 02:02:02, 2016.03.03
03:03:03
};
bool e[] = {true, false, null};
timespan g[] = {1472500, 1472500};
datasource h[] = {123, "texte1", 1.111, 2016.01.01 01:01:01, true};
// You can assign inital values when declaring the array.
int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
string b[] = { "texte 1", "test", "abc" };

Once an array is declared, it can only accept values of the type specified. Example: int a[10] will only accept integer values.

Query expressions

Query expressions can be used to fetch and transform information from any complex data source. These queries can retrieve, sort and filter an array (dictionary, list, etc.). Their goal is, starting from an array, to create a new data source that:  

  • Filters the original array (WHERE clause)
  • Sorts the original array (ORDER BY clause)
  • Extracts a specific property from items in the original array
  • Deduplicates items (DISTINCT option) 
Query ElementDescription
SelectSpecifies the values to extract from the data source. Use the distinct option if you only wish to return unique values. 
FromIdentifies the data source to which the query is applied. 
WhereAllows the filtering of results using inclusion or exclusion rules. 
Order bySorts the data according to one or more fields, in ascending or descending order. Supported keywords: asc, ascending, desc, descending
Important Notes

Although they are powerful, the data source query features come at a huge performance cost. If used incorrectly in a message, these queries can have an important impact on the speed at which messages are prepared. A single query placed in a message sent to a million contacts will have to be processed a million times. Don't hesitate to ask our support team or our analysts for advice when creating messages requiring this level of complexity. 

All these elements come together like this:
select identifier.proprerty1
from identifier in expression
where identifier.propriete1 = valeur
order by (identifier.propriete2 asc)

With :

  • Expression: the structure from which the data will be extracted (array, collection, etc.). 
  • Identifier: the name of the variable that will be used to refer to the data source (in the select, where and order by clauses).  
// Let's suppose the following data source:
[[
datasource Vehicules =
{
{ Brand: "Toyota", Model: "Sienna", Year: 2015},
{ Brand: "Ford", Model: "Fusion", Year: 2013},
{ Brand: "Chevrolet", Model: "Equinox", Year: 2005 },
{ Brand: "Hyundai", Model: "Accent", Year: 2016 },
{ Brand: "Mazda", Model: "CX-5", Year: 2015 },
{ Brand: "Hyundai", Model: "Accent", Year: 2010 }, };
]]

// To select the brands of all the vehicle:
[[
datasource Brands = select car.Brand
from car in Vehicules;
/* The resulting Brands object would contain:  
Toyota
Ford
Chevrolet
Hyundai
Mazda
Hyundai
*/

]]

// To select the unique brands (without duplicates) of all the vehicle
[[
datasource Brands = select distinct car.Brand
from car in Vehicules;
/*
The resulting Brands object would contain:
Toyota
Ford
Chevrolet
Hyundai
Mazda
*/

]]

// To select the unique brands of all the vehicles, from the most recent to the oldest:
[[
datasource Marques = select distinct voiture.Marque
from voiture in Vehicules
order by (voiture.Annee desc);
/*
The resulting Brands object would contain:
Hyundai
Mazda
Toyota
Ford
Chevrolet
*/
]]
// To select the unique brands of all the vehicles, from the most recent to the oldest, excluding those from before 2014 : [[ datasource Brands = select distinct car.Brand from car in Vehicles where (car.year > 2014) order by (car.Year desc); ]] /* The resulting Brands object would contain: Hyundai Mazda Toyota */
// Note that it's possible to clone an array by selecting all its items:
[[
datasource VehiculesCopy = select car from car in Vehicules;
]]


Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.