tuple_string — Convert a tuple into a tuple of strings.
tuple_string converts numbers into strings or modifies strings.
The operator has two parameters:
T is the number or string
that has to be converted.
Format specifies the conversion.
In the following, first some examples for the use of
tuple_string are given and then, the structure of the
Format string is explained in detail.
Examples for the conversion of numbers into strings:
Examples for the modification of strings:
Format string consists of the following four parts:
<flags><field width><precision><conversion characters>
Zero or more flags, in any order, which modify the meaning of the conversion specification. Flags may consist of the following characters:
The result of the conversion is left justified within the field.
The result of a signed conversion
always begins with a sign,
If the first
character of a signed conversion is not a sign, a space character is
prefixed to the result. This means that if the space flag and
+ flag both appear, the space flag is ignored.
The value is to be converted to
an “alternate form”. For
this flag has no effect. For
o conversion (see below), it
increases the precision to force the first digit of the result to be
a zero. For
X conversion (see below), a non-
zero result has
0X prefixed to it. For
conversions, the result always contains a radix character, even if
no digits follow the radix character. For
conversions, trailing zeros are not removed from the result,
contrary to usual behavior.
An optional string of decimal digits to specify a minimum field width. For an output field, if the converted value has fewer characters than the field width, it is padded on the left (or right, if the left-adjustment flag, - has been given) to the field width.
specifies the minimum number of digits to appear for the
X conversions (the field is
padded with leading zeros), the number of digits to appear after the
radix character for the
f conversions, the
maximum number of significant digits for the
or the maximum number of characters to be printed from a string in
s conversion. The precision takes the form of a period
. followed by a decimal digit string. A null digit string
is treated as a zero.
A conversion character indicates the type of conversion to be applied:
The integer argument
is printed in signed decimal (
d), unsigned octal
o), or unsigned hexadecimal notation (
x conversion uses the numbers and letters
0123456789abcdef, and the
X conversion uses the
numbers and letters
0123456789ABCDEF. The precision
component of the argument specifies the minimum number of digits to
appear. If the value being converted can be represented in fewer
digits than the specified minimum, it is expanded with leading
zeroes. The default precision is 1. The result of converting a
zero value with a precision of 0 is no characters.
The floating-point number argument
is printed in decimal notation in the style
where the number of digits after the radix character,
equal to the precision specification. If the precision is omitted
from the argument, six digits are output; if the precision is
explicitly 0, no radix appears.
argument is printed in the style
where there is one digit before the radix character, and the number
of digits after it is equal to the precision. When the precision is
missing, six digits are produced; if the precision is 0, no radix
character appears. The
E conversion character produces a
E introducing the exponent instead of
e. The exponent always contains at least two digits.
However, if the value to be printed requires an exponent greater
than two digits, additional exponent digits are printed as
argument is printed in style
e (or in style
E in the case of a
G conversion character), with
the precision specifying the number of significant digits. The
style used depends on the value converted; style
e is used
only if the exponent resulting from the conversion is less than -4
or greater than or equal to the precision. Trailing zeros are
removed from the result. A radix character appears only if it is
followed by a digit.
The argument is taken to be a string, and characters from the string are printed until the end of the string or the number of characters indicated by the precision specification of the argument is reached. If the precision is omitted from the argument, it is interpreted as infinite and all characters up to the end of the string are printed.
Similar to the
conversion specifier, except that the string can contain
backslash-escape sequences which are then converted to the
characters they represent.
In no case does a nonexistent or insufficient field width cause truncation of a field; if the result of a conversion is wider than the field width, the field is simply expanded to contain the conversion result.
If any of the input tuples is empty, an exception is raised.
HDevelop provides an in-line operation for
which can be used in an expression in the following syntax:
String := T $ Format
→(real / integer / string)
Input tuple converted to strings.
* * ' 23.00' tuple_string (23, '10.2f', String) String := 23$'10.2f' * * '23.00 ' tuple_string (23, '-10.2f', String) String := 23$'-10.2f' * * '4.0000000' tuple_string (4, '.7f', String) String := 4$'.7f' * * ' +1234.568' tuple_string (1234.56789, '+10.3f', String) String := 1234.56789$'+10.3f' * * 'ff' tuple_string (255, 'x', String) String := 255$'x' * * 'FF' tuple_string (255, 'X', String) String := 255$'X' * * '00255' tuple_string (0xff, '.5d', String) String := 0xff$'.5d' * * ' total' tuple_string ('total', '10s', String) String := 'total'$'10s' * * 'total ' tuple_string ('total', '-10s', String) String := 'total'$'-10s' * * 'tot ' tuple_string ('total', '-10.3s', String) String := 'total'$'-10.3s'