Programmer Guide/Command Reference/FORMAT: Difference between revisions

From STX Wiki
Jump to navigationJump to search
(initial import)
 
No edit summary
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
==FORMAT==
{{PG_StringCommands}}
<var>var</var> := FORMAT formatstring arg<sub>1</sub> [ arg<sub>2</sub> ... ]


<code>var := FORMAT formatstring arg1 [arg2 ...]</code>
<code>format</code> formats its arguments, interpreting the first argument as a format string (almost, but not quite unlike the C-language <code>printf</code> command). {{STX}} formats are described in [[Programmer Guide/General Descriptions/Format Strings and Rules|Format Strings and Rules]].


-> var = formatted string
#srateHz := 44100
#SRSTR := FORMAT '%.1f kHz' '$#srateHz/1000'
// Here, the variable <code>#SRSTR</code> is assigned the string '<code>44.1 kHz</code>'.


Assign values to a variable using a format string to format the result. Formats are described in Format Strings and Rules.
Note that, unlike with the C-language <code>printf</code> formats, the first argument <code>arg<sub>1</sub></code> is ''mandatory'' with the {{STX}} <code>format</code> command:
#str := format 'How much wood would a wood chuck chuck?' 'dummy'


Even if you are using a format string which does not need an argument, the first argument is mandatory.<pre>
Here, the dummy argument (in our case, the string constant <code>'dummy'</code>) is mandatory, although it will not influence the result of the string "How much wood would a wood chuck chuck?" being assigned to the variable <var>#str</var>.
#srateHz := 44100#SRSTR := FORMAT '%.1f kHz' '$#srateHz/1000'
</pre>
The variable <code>#SRSTR</code> is assigned the value '<code>44.1 kHz</code>'.

Latest revision as of 11:20, 4 March 2016

var := FORMAT formatstring arg1 [ arg2 ... ]

format formats its arguments, interpreting the first argument as a format string (almost, but not quite unlike the C-language printf command). STx formats are described in Format Strings and Rules.

#srateHz := 44100
#SRSTR := FORMAT '%.1f kHz' '$#srateHz/1000'
// Here, the variable #SRSTR is assigned the string '44.1 kHz'.

Note that, unlike with the C-language printf formats, the first argument arg1 is mandatory with the STx format command:

#str := format 'How much wood would a wood chuck chuck?' 'dummy'

Here, the dummy argument (in our case, the string constant 'dummy') is mandatory, although it will not influence the result of the string "How much wood would a wood chuck chuck?" being assigned to the variable #str.

Navigation menu

Personal tools