Extensions.Util.StringFormat

From emotive
Revision as of 05:01, 17 February 2020 by Ntr (talk | contribs) (Edited by Ngoc Tran. According to special by ISO 13209-4)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.

Icons Note.png 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:
\n New line is added into the string
The format specifier has the following syntax:
{argument index[:conversion[precision]]}
Argument index:
Valid argument values are [0,n]
Supported Conversions:

  • 'B' - Boolean - a given precision takes no effect
  • 'S' - String - a given precision takes no effect
  • 'D' - Decimal
  • 'X' - Hexadecimal
  • 'E' - Exponent - default precision is 6
  • 'F' - Fixed point - default precision is 2

In case no conversion is defined the default conversion is String. If the conversion does not fit the given term a StringFormatException is thrown.
Precision:
Valid precision values are [1,n]
Samples with pseudo code with de-DE:

  • “{0}”,”Hallo”
    • Hallo
  • “{0} Peter”,”Hallo”
    • Hallo Peter
  • “{0} Peter, {0} {1}”, “Hallo”,”Klaus”
    • Hallo Peter, Hallo Klaus
  • “{0} Peter, {0} {1} {0}”, “Hallo”,”Klaus”
    • Hallo Peter, Hallo Klaus Hallo
  • “{0} Peter, {0} {1}”, “Hallo”,”Klaus”, ”NN”
    • Hallo Peter, Hallo Klaus
  • “{0} Peter\n{0} {1}”, “Hallo”,”Klaus”
    • Hallo Peter, Hallo Klaus
  • “Wert ist [{0:B}]”, false
    • Wert ist [False]
  • “Wert ist [{0:B10}]”, true
    • Wert ist [True]
  • “Wert ist [{0:D}]”, 12
    • Wert ist [12]
  • “Wert ist [{0:D5}]”, 12
    • Wert ist [00012]
  • “Wert ist [{0:X}]”, 255
    • Wert ist [FF]
  • “Wert ist [{0:X3}]”, 255
    • Wert ist [0FF]
  • “Wert ist [{0:X3}]”, 255
    • Wert ist [0FF]
  • “Wert ist [{0:E}]”, 1.234
    • Wert ist [1,234000E+000]
  • “Wert ist [{0:E}]”, 1.2345678
    • Wert ist [1,234568E+000]
  • “Wert ist [{0:E10}]”, 1.2345678
    • Wert ist [1,2345678000E+000]
  • “Wert ist [{0:E}]”, 12
    • Wert ist [1,200000E+001]
  • “Wert ist [{0:F}]”, 1.2345678
    • Wert ist [1,23]
  • “Wert ist [{0:F}]”, 123456.78
    • Wert ist [123456,78]
  • “Wert ist [{0:F1}]”, 1.2345678
    • Wert ist [1,2]
  • “Wert ist [{0:F5}]”, 1.2345678
    • Wert ist [1,23457]
  • “Wert ist [{0:F10}]”, 1.2345678
    • Wert ist [1,2345678000]
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