Operator Scope of Action:
Operator First Added:
In most cases it is better to use newer Interval.format() operator for this task.
The operator format() converts various Tinderbox objects to strings. In quoted (") string arguments a
\" is converted into a quotation mark (a.k.a. double quote),
\n to a carriage return and
\t to a tab.
The argument data is usually an attribute reference or expression. An attribute reference can take both short and long forms:
$MySet (i.e. the current note's $MySet)
$MySet(Test) (i.e. set $MySet data from note 'Test')
The meaning of formatString depends on the type of object represented by what. Tinderbox data types Date, Set and Number are handled using different sets of arguments as described below.
This function is being supplemented by per-data-type .format() dot operators which are usually more flexible when writing non-trivial code: links to per-data-type dot operators are added below.
$MyString = format($Created,"L");
gets the note's creation date and formats it as a "long local date" such as "Sunday, 23 March, 2007".
Also use Date.format("formatString").
The process preserves original data; duplicate values in lists are maintained. For example
$MyString = format($KeyAttributes,", ");
converts Displayed Attributes to a comma+space-separated list. To put each item on a separate line use this:
$MyString = format($KeyAttributes,"\n");
Thus $Text may be created from concatenation of other texts:
$Text = format(collect(children, $Text),"\n");
To strip duplicates from a List, do not use format(). Instead, simply set a Set attribute to the contents of the List attribute (or any function/expression returning List-type data).
Also use List.format("formatString").
Optionally, you may supply five arguments to format the set as an HTML list:
$MyString = format($Classes,"<ul>","<li>","</li>","</ul>");
will return HTML code for a bulleted list with each set member marked up as a list item. Note that the tags must be in double quotes. To have each element on a separate line and indent the items add tabs and line breaks:
$MyString = format($Classes,"<ul>\n","\t<li>","</li>\n","</ul>\n");
To make this easier to use in a code export context, you might pass the output of format into another attribute and call the latter within the template with a ^value()^ code. By a repeat call to format it is possible to export lists of links.
If data is a number, then the arguments are numeric and interpreted as follows:
The precision argument controls the number of decimal places returned. The optional width argument allows the returned value to be a string left padded with spaces, e.g. to return a string with the same number of characters as submitted.
For example, if $MyNumber is 3.1415927, then
$MyString = format($MyNumber,2,7); is " 3.14" (3 spaces + number + period + 3 numbers = 7)
$MyString = format($MyNumber,2); is 3.14
$MyString = format($MyNumber,0); is 3
$MyString = format($MyNumber,0,2); is ' 3' (two left-padding spaces)
$MyString = format(5.1415927,2); is 5.14
Note that with widthN, decimal character is not counted as part of the number.
If the optional padStr is given, this specifies the character used for padding. The default is a space:
$MyString = format(7,0,3); gives " 7"
$MyString = 7.format(7,0,3,"0"); gives "007"
$MyString = format(7,0,3,"#"); gives "##7"
An alternate number format is offered using a quoted format string:
Currently only one such string is supported "L". This will return a string of the number formatted with (OS) locale-dependent group & decimal delimiters. For example, for the US locale these are a comma and a period; in other locales they may vary.
Also use Number.format(decimalsN,widthN).
If data is color type, format strings are ignored:
The operator returns the colour color in hex form, e.g. "#ff00ff", regardless of whether the stored value is hex or a named Tinderbox colour.
$MyString = format($MyColor)
is "#ff00ff" if $MyColor is "purple"
Also use Color.format().
Also use Interval.format().