Difference between revisions of "Extensions.Util.StringFormat"
(Created page with "{{DISPLAYTITLE: '''StringFormat'''}}Category:Util == Classification == {{ClassificationActivity | StringFormat | UPDATING...<!--Create an event source for change event-->...") |
(Edited by Ngoc Tran. According to special by ISO 13209-4) |
||
(4 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE: '''StringFormat'''}}[[Category:Util]] | {{DISPLAYTITLE: '''StringFormat'''}}[[Category:Util]] | ||
== Classification == | == Classification == | ||
− | {{ClassificationActivity | StringFormat | | + | {{ClassificationActivity | StringFormat| Converts the given terms to format specified strings | [[Term]] | [[Extensions.Util|OTX Util extension]] | [[Extensions.Util#Terms|Util related terms]] | [[Extensions.Util.StringFormatException|StringFormatException]] | - }} |
== OTL Syntax == | == OTL Syntax == | ||
− | |||
<syntaxhighlight lang="java" enclose="div" style="font-size: medium;"> | <syntaxhighlight lang="java" enclose="div" style="font-size: medium;"> | ||
− | + | StringTerm = Util.StringFormat(StringTerm format, StringTerm locale, { SimpleTerm[] argument }); | |
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
== Description == | == Description == | ||
− | + | The OTX '''StringFormat''' term converts the given terms to format specified strings and inserts them into another string. | |
− | The OTX ''' | ||
− | + | {{TermReturnValue| [[Core.DataTypes.SimpleDataType.String|String]] | The string is created from the given terms and format specified strings.}} | |
− | |||
− | {{TermReturnValue| [[ | ||
== Properties == | == Properties == | ||
− | |||
{| {{TableHeader}} | {| {{TableHeader}} | ||
{{TableRowPropertiesHeader}} | {{TableRowPropertiesHeader}} | ||
− | {{TableRowPropertie1| | + | {{TableRowPropertie2| Format| [[Core.DataTypes.SimpleDataType.String|String]] | [[Term]] | - | [1..1] | The format is a [[String|StringTerm]] that can contain one or more format specifiers. The opening and closing curly braces are special characters and will only be used for defining format specifiers within the string. If the curly braces are used incorrectly, a [[Extensions.Util.StringFormatException|StringFormatException]] is thrown. <br/> |
+ | In the format string supports the following escape codes: <br/> | ||
+ | \n New line is added into the string <br/> | ||
+ | The format specifier has the following syntax: <br/> | ||
+ | {argument index[:conversion[precision]]} <br/> | ||
+ | Argument index: <br/> | ||
+ | Valid argument values are [0,n] <br/> | ||
+ | Supported Conversions: <br/> | ||
+ | * 'B' - Boolean - a given precision takes no effect <br/> | ||
+ | * 'S' - String - a given precision takes no effect <br/> | ||
+ | * 'D' - Decimal <br/> | ||
+ | * 'X' - Hexadecimal <br/> | ||
+ | * 'E' - Exponent - default precision is 6 <br/> | ||
+ | * 'F' - Fixed point - default precision is 2 <br/> | ||
+ | In case no conversion is defined the default conversion is [[String]]. If the conversion does not fit the given term a [[Extensions.Util.StringFormatException|StringFormatException]] is thrown. <br/> | ||
+ | Precision: <br/> | ||
+ | Valid precision values are [1,n] <br/> | ||
+ | Samples with pseudo code with de-DE: <br/> | ||
+ | * “{0}”,”Hallo” | ||
+ | ** Hallo <br/> | ||
+ | * “{0} Peter”,”Hallo” | ||
+ | ** Hallo Peter <br/> | ||
+ | * “{0} Peter, {0} {1}”, “Hallo”,”Klaus” | ||
+ | ** Hallo Peter, Hallo Klaus <br/> | ||
+ | * “{0} Peter, {0} {1} {0}”, “Hallo”,”Klaus” | ||
+ | ** Hallo Peter, Hallo Klaus Hallo <br/> | ||
+ | * “{0} Peter, {0} {1}”, “Hallo”,”Klaus”, ”NN” | ||
+ | ** Hallo Peter, Hallo Klaus <br/> | ||
+ | * “{0} Peter\n{0} {1}”, “Hallo”,”Klaus” | ||
+ | ** Hallo Peter, Hallo Klaus <br/> | ||
+ | * “Wert ist [{0:B}]”, false | ||
+ | ** Wert ist [False] <br/> | ||
+ | * “Wert ist [{0:B10}]”, true | ||
+ | ** Wert ist [True] <br/> | ||
+ | * “Wert ist [{0:D}]”, 12 | ||
+ | ** Wert ist [12] <br/> | ||
+ | * “Wert ist [{0:D5}]”, 12 | ||
+ | ** Wert ist [00012] <br/> | ||
+ | * “Wert ist [{0:X}]”, 255 | ||
+ | ** Wert ist [FF] <br/> | ||
+ | * “Wert ist [{0:X3}]”, 255 | ||
+ | ** Wert ist [0FF] <br/> | ||
+ | * “Wert ist [{0:X3}]”, 255 | ||
+ | ** Wert ist [0FF] <br/> | ||
+ | * “Wert ist [{0:E}]”, 1.234 | ||
+ | ** Wert ist [1,234000E+000] <br/> | ||
+ | * “Wert ist [{0:E}]”, 1.2345678 | ||
+ | ** Wert ist [1,234568E+000] <br/> | ||
+ | * “Wert ist [{0:E10}]”, 1.2345678 | ||
+ | ** Wert ist [1,2345678000E+000] <br/> | ||
+ | * “Wert ist [{0:E}]”, 12 | ||
+ | ** Wert ist [1,200000E+001] <br/> | ||
+ | * “Wert ist [{0:F}]”, 1.2345678 | ||
+ | ** Wert ist [1,23] <br/> | ||
+ | * “Wert ist [{0:F}]”, 123456.78 | ||
+ | ** Wert ist [123456,78] <br/> | ||
+ | * “Wert ist [{0:F1}]”, 1.2345678 | ||
+ | ** Wert ist [1,2] <br/> | ||
+ | * “Wert ist [{0:F5}]”, 1.2345678 | ||
+ | ** Wert ist [1,23457] <br/> | ||
+ | * “Wert ist [{0:F10}]”, 1.2345678 | ||
+ | ** Wert ist [1,2345678000] <br/> | ||
+ | }} | ||
+ | {{TableRowPropertie1|Locale| [[Core.DataTypes.SimpleDataType.String|String]] | [[Term]] | - | [0..1] | The locale to apply during formatting. The format is identical to that used in [[Extensions.I18n.GetCurrentLocale|'''i18n:GetCurrentLocale''']]. <br/> | ||
+ | If the locale is not given, empty or not supported, the default locale of the runtime system is taken. The current language can be identified by calling [[Extensions.I18n.GetCurrentLocale|'''i18n:GetCurrentLocale''']].}} | ||
+ | {{TableRowPropertie2| Argument| [[Core.DataTypes.SimpleDataType|Simple]] | [[Term]] | - | [0..*] | Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. If more identical format specifiers are used in the format string, the appropriate arguments are inserted multiple. | ||
+ | |||
+ | The maximum number of arguments is limited of resources of the used run time system. A recommendation is not to use more than 10 arguments.}} | ||
|} | |} | ||
− | |||
== OTL Examples == | == OTL Examples == | ||
− | |||
<syntaxhighlight lang="java" enclose="div" style="font-size: medium;"> | <syntaxhighlight lang="java" enclose="div" style="font-size: medium;"> | ||
− | + | String String1; | |
− | + | String Locale = ""; | |
− | + | ||
+ | /// Flow | ||
− | + | Locale = I18n.GetCurrentLocale(); | |
− | + | // Result: String1 = "Hello Peter, Hello Klaus Hello" | |
− | { | + | String1 = Util.StringFormat("{0} Peter, {0} {1} {0}", Locale, {"Hello", "Klaus"}); |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
== See also == | == See also == | ||
[[Extensions.Util.Compare|Compare]] <br/> | [[Extensions.Util.Compare|Compare]] <br/> | ||
[[Extensions.Util.CopyByteField|CopyByteField]] <br/> | [[Extensions.Util.CopyByteField|CopyByteField]] <br/> | ||
+ | [[Extensions.Util.GetRandomNumber|GetRandomNumber]] <br/> | ||
[[Extensions.Util.IsInitialized|IsInitialized]] <br/> | [[Extensions.Util.IsInitialized|IsInitialized]] <br/> | ||
[[Extensions.Util.ListIndexOf|ListIndexOf]] <br/> | [[Extensions.Util.ListIndexOf|ListIndexOf]] <br/> |
Latest revision as of 04:01, 17 February 2020
Contents
Classification
Name | StringFormat |
Short Description | Converts the given terms to format specified strings |
Class | Term |
Extension | OTX Util extension |
Group | Util related terms |
Exceptions | StringFormatException |
Checker Rules | - |
Standard Compliant | Yes |
OTL Syntax
StringTerm = Util.StringFormat(StringTerm format, StringTerm locale, { SimpleTerm[] argument });
Description
The OTX StringFormat term converts the given terms to format specified strings and inserts them into another string.
Return Value
The Term returns the value, see table below.
![]()
In OTX, Terms are categorized according to its return data type!
Data Type | Description |
String | The string is created from the given terms and format specified strings. |
Properties
Name | Data Type | Class | Default | Cardinality | Description |
Format | String | Term | - | [1..1] | The format is a StringTerm that can contain one or more format specifiers. The opening and closing curly braces are special characters and will only be used for defining format specifiers within the string. If the curly braces are used incorrectly, a StringFormatException is thrown. In the format string supports the following escape codes:
In case no conversion is defined the default conversion is String. If the conversion does not fit the given term a StringFormatException is thrown.
|
Locale | String | Term | - | [0..1] | The locale to apply during formatting. The format is identical to that used in i18n:GetCurrentLocale. If the locale is not given, empty or not supported, the default locale of the runtime system is taken. The current language can be identified by calling i18n:GetCurrentLocale. |
Argument | Simple | Term | - | [0..*] | Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. If more identical format specifiers are used in the format string, the appropriate arguments are inserted multiple.
The maximum number of arguments is limited of resources of the used run time system. A recommendation is not to use more than 10 arguments. |
OTL Examples
String String1;
String Locale = "";
/// Flow
Locale = I18n.GetCurrentLocale();
// Result: String1 = "Hello Peter, Hello Klaus Hello"
String1 = Util.StringFormat("{0} Peter, {0} {1} {0}", Locale, {"Hello", "Klaus"});
See also
Compare
CopyByteField
GetRandomNumber
IsInitialized
ListIndexOf
ListIndexOfAny
ListReverse
ListSort
Max
Min