GetText(), T()
Summary
Returns a string, formatted and substituted according to the format and the arguments.
Syntax
text = GetText(string format, array args[, string context])
| Argument | Contents |
|---|---|
| format | A string format, that uses format specifiers such as %s (string), %d (integers), and %6.2lf(long float), to define the string. |
| args | Optional. An array in which each element is a macro expression in Caliper Script. |
No options are currently supported.
Returns
A formatted string, with all format specifiers replaced by the corresponding macro expression, (i.e. the values of array elements in the 2nd argument).
Notes
-
The format string is replaced with string defined in the args array.
-
Format specifiers%1,...,%9 are substituted first; followed by other %* substitution.
-
A double %% will appear as a single % in the output and will not use any arguments from the args array.
-
The expression in the args array must return values that match the type specified by the corresponding %* format specifier in the output string. Currently, only string and numerical data types are supported.
-
Most of the normal specifiers supported by C function printf(...) can be used, for example, %.2f, %g, etc
Examples
set_name = "Selection"
count = GetSetCount(set_name)
text1 = "There are %1 records in set %2"
text2 = "Set %2 has %1 records"
new_text1 = GetText(text1 , {count, set_name}) // new_text1 is "There are 4 records in set Selection"
new_text2 = GetText(text2 , {count, set_name}) // new_text2 is "Set Selection has 4 records"
avg = 1.458894
property = "sale"
text = "The average %s is %.2lf"
new_text = GetText(text , { property, avg }) // new_text is The average sale is " 1.46"
Error Codes
| Error Type | Meaning |
|---|---|
| Error | Invalid prototype string for format tags (%s) or mismatch in data type. The order of the format specifiers does not match the order of the args types |