str, soft
These functions convert variables of any type to strings, including void values. The function str returns strings as quoted strings whereas soft returns strings as softquoted strings. If only one parameter containing the value to provide, then following default rules are applied:
Original Type | Approach |
---|---|
boolean | Converts to true or false, using lower case letters |
date | Converts to dates in text format using universal format YYYY-MM-DD, e.g 2020-12-31 |
numeral | Converts to numbers in text format using decimal point "." and without thousand spearators. |
parameter set | Converts to values arranged inside braces and separated with commas. Strings and dates are put into single quotation marks. |
string | Contents stay unchanged |
void | Converts to '# Invalid Value #', in case the void value does not come along with a different message inside '#' signs. |
With the additional 1-3 parameters, specific formatting templates (patterns), options and placeholder characters can be applied. 2 approaches exist:
Indirect parameter passing is disabled
1-4
No. | Type | Description |
---|---|---|
1 input |
all types | Value to convert Value to check. |
Opt. 2 input |
string | Formatting template The formatting template is a string which containing patterns to convert a value of a specific type to a string. Different rules
and patterns apply for the different types to convert. This means that you cannot use the same formatting template to convert a numeral to
a string as well as a date to a string successfully because numeral formatting rules things like decimal points, number of digits behind
decimal points, etc, where date formatting rules things like arranging date/month/year, using numbered or written months, time of day, etc.
|
Alt. 2 input |
parameter set | Smart formatting parameters In some cases, you wish to convert values of different types to string and need to apply different formatting templatess for them.
In this case, put the following contents into a 2-level nested parameter set and pass it as 2nd function parameter to this function. |
Opt. 3 input |
parameter set or string | Formatting option or locale For converting numerals, booleans and dates, a locale (related to countries and languages) information is expected. |
Opt. 4 input |
string | Placeholder symbol Applicable to formatting numerals, strings and voids (which are converted to strings). In order to use these symbols, the formatting template (2nd function parameter) must provide space for them, e.g. with sufficient number of characters provided in string formatting, and use of question marks in number to string conversion. Default value: space symbol ' ' |
Type | Description |
---|---|
string | Result Converted and formatted string |
echo( str( Abc ), ", ", str( 123.45 ), ", ", str(true) );
echo( str(date('14.juillet.2020')), ", ", str( date('1. Aug 20 22:30')), ", ", str( time( '10:15' ) ) );
echo( null() ); // void
echo( {a,1,date(today),false} ); // void
Abc, 123.45, true
2020-07-14, 2020-08-01 22:30:00, 10:15:00
# Invalid Value #
{'a',1,'2024-07-14',false}