This version is out of date, covering development from v9.0.0 to v9.3.0. It is maintained here only for inbound reference links from elsewhere. It is no longer actively updated.

Jump to the current version of aTbRef

Tinderbox v9 Icon

Concatenation versus addition

In Tinderbox, the plus symbol (+) is used both to concatenate (join) strings of text and to sum figures. Thus

$MyString = "My favourite colour is " + $FavouriteColour 

$MyNumber = 4 + 3 

Nothing untoward there, not least as the resulting data type (as implied here by the left side attribute name) helps Tinderbox guess the user's intent. But what about:

$MyString = "6" + 4 

Is it "64", 64, "10" or 10? As the stated attribute is String-type, the result is a string. As one of the right side arguments is a string, then a concatenation is used. If both (all) arguments are numbers, then an addition occurs before being saved as a string:

$MyString = "6" + 4 gives "64"

$MyString = 6 + 4 gives "10"

$MyString = 6 + "4" gives "64"

$MyString = "6" + "4" gives "64"

In earlier versions of Tinderbox, there was no need to quote strings and Tinderbox guessed string/number by context. Since then, as the action code has got richer, it has become harder to divine the user's intent, thus the move to expecting text to be placed in double quotes. Incidentally it also makes it easier to indicate intent with regard to leading/trailing white space.

Thus, when using the '+' operator try to ensure Tinderbox is not having to guess too hard as to the desired outcome.

If necessary use parentheses to help indicate intended operator precedence to Tinderbox if it is getting things wrong.

Dates and Strings

Expressions in which a date is added to a string. In the following the value of $Name is "Created"

$String=$Name + $Created <- a string "Created08/07/2010 08:27"

$String=$Name + " " + $Created <- a string "Created 08/07/2010 08:27"

In the above example the date time format is the user's host OS short date/time format so will vary by locale. The date shown equates to format($Date,"l t"), i.e. local short date space local time (see format(), date formats). Use format() with the date attribute if some other date/time formatting is required.

Note also above how a joining space needs to be provided. Note also that adding a string to a date continues to return a date, adding a date to a string returns a string:

$Date+"3 days" <- a date: 3/29/10

"3 Days "+$Date <- a string: 3 Days 3/26/10

"3 Days"+" "+$Date <- a string: 3 Days 3/26/10

The first above assumes the string being added contains logical date-related content.

A Tinderbox Reference File : Actions & Rules : Concatenation versus addition