String formatter¶
Function
It applies formatting to one or more input variables according to a customizable rule.
It can also be used to format and parameterize SQL queries, for example to be used in database objects (see DataStore (database)).
Properties
Properties |
Description |
---|---|
Format |
Formatting rule. For references to variables, it accepts the following placeholders:
Placeholders must follow the Note for every |
Mode |
|
Source
One or more variables, identified by a placeholder with an index number, with the following format {index}
. The index number is progressive, must be an integer greater than zero ({0}
).
Placeholders can appear in any order in the formatting rule (e.g.: The minimum value of {3}, {0} and {2} is {1}
).
Allowed Formatting Values
The format
placeholder accepts a subset of values required by the .NET framework notation for the String.Format
method.
Data type: DateTime
Example data: 23/04/2021 17:25:31, session with 60 minutes TimeZone offset.
Format |
Description |
Example |
---|---|---|
g |
Short date and time, local |
|
F |
Extended date and time, local |
|
X |
Short date and time, UTC |
|
x |
Extended date and time, UTC |
|
U |
Complete Universal Date and Time, UTC |
|
p |
Short date, local |
|
P |
Extended date, local |
|
d |
Short date, UTC |
|
D |
Extended date, UTC |
|
t |
Short time, local |
|
T |
Extended time, local |
|
h |
Short time, UTC |
|
H |
Extended time, UTC |
|
Data types: numeric (Double Float Int16 Int32 Int64 Integer UInt16 UInt32 UInt64 UInteger)
Format |
Description |
Example |
---|---|---|
d |
Numerical, without thousands separator. After the format placeholder, the number of decimal places is configured with an integer (without padding). |
|
n |
Numerical, with thousands separator. After the format placeholder, the number of decimal places is configured with an integer (without padding). |
|
e |
Exponential notation. After the format placeholder, the number of significant numbers is configured with an integer. |
|
f |
Fixed point notation. After the format placeholder, the exact number of decimal places is configured with an integer. |
|
p |
Percentage. After the format placeholder, an integer is used to configure the number of decimal places. |
|
x |
Hexadecimal notation |
255 ► ff |
b |
Binary notation |
107 ► 1101011 |
o |
Octal Notation |
56 ► 70 |
Data types: Duration and Timespan
Format |
Description |
Example |
---|---|---|
c |
Constant format: [-][d’.’]hh’:’mm’:’ss[‘.’fffffff] |
|
g |
General short format: [-][d’.’]hh’:’mm’:’ss[‘.’fffffff] |
|
G |
Extended general format: [-][d’.’]hh’:’mm’:’ss[‘.’fffffff] |
|
Data type: String
Format |
Description |
Example |
---|---|---|
l |
All lowercase |
grüßEN ► grüßen |
u |
All uppercase |
grüßEN ► GRÜSSEN |
t |
All first letters uppercase |
grüßEN erdbewohner ► Grüßen Erdbewohner |
f |
Case independent |
grüßEN ► grüssen |
Data type: ANSI SQL
Format |
Description |
Example |
---|---|---|
sql_identifier |
Formats a given String or LocalizedText as a table or column identifier. |
- |
sql_literal |
Formats the value of a variable as an SQL literal value (Number, String, date, time, etc.). |
- |
Inverse Formatting
Inverse formatting is defined as the functionality that allows the user to modify a formatted value at runtime to replace it with a new value that the application shows with the same formatting at runtime.
To allow this mechanism via the string formatter, the following conditions must be met:
The dynamic link mode of the converter must be read and write.
The Format field must have only one placeholder, i.e. only one source.
Note
the placeholder can have a suffix and/or prefix; it can also be set with a format string, for example,
{0:n}
.
Output
The string entered in the Format property, based on the formatting rules with values in place of the placeholder(s).
Logical representation
The following image illustrates an example of a logical conversion in the advanced dynamic link editor.
Examples of SQL Queries
Parameterize the name of the internal column with the condition:
SELECT * FROM Table1 WHERE {0:sql_identifier} > 5
Comparison with a data variable:
SELECT * FROM AlarmsDatalogger WHERE Time > {0:sql_literal}
Parameterize the LIKE
operator:
SELECT * FROM AlarmsDatalogger WHERE Name LIKE '{0}'
Parameterize part of a query with a placeholder:
SELECT * FROM Table1 {0}
The placeholder with index 0 is linked to a project string variable and parameterizes a column; the placeholder with index 1 is linked to a numeric variable that represents the value for the comparison operator >
:
SELECT * FROM {0:sql_identifier} WHERE Column1 > {1:sql_literal}
Parameterize the table name, the column and also the LIKE
operator:
SELECT {0:sql_identifier} FROM {1:sql_identifier} WHERE {0:sql_identifier} LIKE '{2}'