This version is out of date, covering development from v4.6.0 to v4.7.1. It is maintained here only for inbound reference links from elsewhere.
Jump to the current version of aTbRef.
|A Tinderbox Reference File : Objects & Concepts : Coding conventions : Strings in Tinderbox coding - quoting and escaping||aTbRef Site Map|
Strings in Tinderbox coding - quoting and escaping
From version 4 onwards Tinderbox has moved towards a convention of using double quotes to enclose string literals (i.e. text) when used in Tinderbox codes. An example for ambiguity is where we wish to clarify that we mean 'yesterday' as the word yesterday as opposed to the Tinderbox date placeholder 'yesterday' that is used to subtract one day in doing date calculations. In such a scenario with want to ensure the first instance is quoted and the later isn't, thus:
$DisplayExpression = "Yesterday is: " + date(yesterday)
In many contexts the app with still guess - usually correctly - if quotes aren't used. The reason for the change in convention is the increase in the scope of coding that Tinderbox offers and with it the scope for unintended consequences if the app must figure out what is text and what is not. As a plus sign may be either a potential string concatenator (joiner) or an addition sign and a dash be a minus sign or hyphen, then quoting strings also helps when the app must coerce numbers to strings and vice versa.
Although the advised norm for enclosing string literals is to use double quotes, Tinderbox can handle balanced single or double quotes as text string delimiters. This can be helpful when trying to handle strings that must use double quotes - e.g. the quotes surrounding HTML attributes:
$MyString = '<div width="' + $ItemWidth + '">';
|Up: Coding conventions|
|Previous: Case-sensitivity||Next: Single and double quotes|
Licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0 License
[See aTbRef CC licence Attribution/Waiver info info]