String formatter
Modify the formatting of one or more values according to a customizable rule.
You can use the string formatter to:
- Add characters before or after a value, if the value of the source variable is numeric.
- Format and parameterize SQL queries to use in database objects.
- Link multiple strings in a series.
- Apply numeric formatting, such as decimal places or float rounding.
Properties
Property | Description |
---|---|
Format | The formatting rule for variable reference:
|
Mode | The direction of the dynamic link:
|
Source
Source is one or more variables, identified by a placeholder with an
{index number}
. The index number is progressive and must be an integer greater than zero {0}
. You can use placeholders in any order in the formatting rule. For example, the minimum value of {3}, {0} and {2} is {1}
is a valid syntax.You can nest placeholders in the formatting string
{index,alignment:format}
to dynamically change the formatting of the displayed data.Nested placeholders examples:
- {0:f{1}}
- The variable value linked with{1}defines the number of decimal places.
- {0:{1}{2}}
- The variable value linked with{1}defines the numeric data type.
- The variable value linked with{2}defines the number of decimal places.
- {0,{1}:{2}{3}}
- The variable value linked with{1}defines the alignment.
- The variable value linked with{2}defines the numeric data type.
- The variable value linked with{2}defines the number of decimal places.
Data types
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 |
|
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 |
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] |
|
Format | Description | Example |
---|---|---|
l | All lowercase. | grüßEN ► grüßen |
u | All uppercase. | grüßEN ► GRÜSSEN |
t | All first letters uppercase. | grüßEN ► GRÜSSEN |
f | Case independent. | grüßEN ► grüssen |
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 , and so on). | - |
SQL queries examples
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 a 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}'
Path formatting
Consider these path formatting capabilities:
- To format a string as a file path, you can use this syntax:{index,alignment:.filepath}
- Input
- ns=5;%PROJECTDIR%/Logo.svg
- Output
- C:\Users\UserName\AppData\Local\Rockwell Automation\FactoryTalk Optix\Emulator\Projects\ProjectName\ProjectFiles\Logo.svg
- To format a string as a URI, you can use this syntax:{index,alignment:.uri}
- Input
- ns=5;%PROJECTDIR%/Logo.svg
- Output
- file:///C:/Users/UserName/AppData/Local/Rockwell Automation/FactoryTalk Optix/Emulator/Projects/ProjectName/ProjectFiles/Logo.svg
- To format a part of a path, you can use this syntax:file:///C:/Reports/Report.{0}.pdf
Inverse formatting
The inverse formatting feature allows you to modify a formatted value at runtime to replace the value with a new value that the application displays with the same formatting at runtime.
The inverse formatting feature requires the following settings to operate correctly:
- The dynamic linkModeof the converter must beRead/Write.
- TheFormatfield must have only one placeholder or source. The placeholder can have a suffix and/or prefix and be set with a format string such as{0:n}.
Output
The string entered in the
Format
property, based on the formatting rules with values in place of the placeholder or placeholders.Example
Provide Feedback