This link in the help...
ms-help://borland.bds5/delphivclwin32/System__AnsiString__Format.html
..says...
"For information on how System::AnsiString::Format assembles a final
string from its format string and arguments, see
System::AnsiString::Format Strings. "
..but I can't find that!
-Roddy
> I'm trying to use the AnsiString::Format method
A side issue: is there an equivalent to Format that works like sscanf -
filling an array of TVarRecs with the results parsed from an input
string?
- Roddy
> A side issue: is there an equivalent to Format that works like sscanf
No.
Gambit
> This link in the help...
>
> ms-help://borland.bds5/delphivclwin32/System__AnsiString__Format.html
>
> ..says...
>
> "For information on how System::AnsiString::Format assembles
> a final string from its format string and arguments, see
> System::AnsiString::Format Strings. "
>
> ..but I can't find that!
Here is the documentation from BCB 6:
-----
Format strings
Format strings specify required formats to general-purpose formatting
routines.
Description
Format strings passed to the string formatting routines contain two types of
objects -- literal characters and format specifiers. Literal characters are
copied verbatim to the resulting string. Format specifiers fetch arguments
from the argument list and apply formatting to them.
Format specifiers have the following form:
"%" [index ":"] ["-"] [width] ["." prec] type
A format specifier begins with a % character. After the % come the
following, in this order:
- An optional argument zero-offset index specifier (that is, the first
item has index 0), [index ":"]
- An optional left justification indicator, ["-"]
- An optional width specifier, [width]
- An optional precision specifier, ["." prec]
- The conversion type character, type
The following table summarizes the possible values for type:
d Decimal.
The argument must be an integer value. The value is converted to a string of
decimal digits. If the format string contains a precision specifier, it
indicates that the resulting string must contain at least the specified
number of digits; if the value has less digits, the resulting string is
left-padded with zeros.
u Unsigned decimal.
Similar to 'd' but no sign is output.
e Scientific.
The argument must be a floating-point value. The value is converted to a
string of the form "-d.ddd...E+ddd". The resulting string starts with a
minus sign if the number is negative. One digit always precedes the decimal
point.The total number of digits in the resulting string (including the one
before the decimal point) is given by the precision specifier in the format
string-a default precision of 15 is assumed if no precision specifier is
present. The "E" exponent character in the resulting string is always
followed by a plus or minus sign and at least three digits.
f Fixed.
The argument must be a floating-point value. The value is converted to a
string of the form "-ddd.ddd...". The resulting string starts with a minus
sign if the number is negative.The number of digits after the decimal point
is given by the precision specifier in the format string-a default of 2
decimal digits is assumed if no precision specifier is present.
g General.
The argument must be a floating-point value. The value is converted to the
shortest possible decimal string using fixed or scientific format. The
number of significant digits in the resulting string is given by the
precision specifier in the format string-a default precision of 15 is
assumed if no precision specifier is present.Trailing zeros are removed from
the resulting string, and a decimal point appears only if necessary. The
resulting string uses fixed point format if the number of digits to the left
of the decimal point in the value is less than or equal to the specified
precision, and if the value is greater than or equal to 0.00001. Otherwise
the resulting string uses scientific format.
n Number.
The argument must be a floating-point value. The value is converted to a
string of the form "-d,ddd,ddd.ddd...". The "n" format corresponds to the
"f" format, except that the resulting string contains thousand separators.
m Money.
The argument must be a floating-point value. The value is converted to a
string that represents a currency amount. The conversion is controlled by
the CurrencyString, CurrencyFormat, NegCurrFormat, ThousandSeparator,
DecimalSeparator, and CurrencyDecimals global variables, all of which are
initialized from the Currency Format in the International section of the
Windows Control Panel. If the format string contains a precision specifier,
it overrides the value given by the CurrencyDecimals global variable.
p Pointer.
The argument must be a pointer value. The value is converted to an 8
character string that represents the pointers value in hexadecimal.
s String.
The argument must be a character, a string, or a PChar value. The string or
character is inserted in place of the format specifier. The precision
specifier, if present in the format string, specifies the maximum length of
the resulting string. If the argument is a string that is longer than this
maximum, the string is truncated.
x Hexadecimal.
The argument must be an integer value. The value is converted to a string of
hexadecimal digits. If the format string contains a precision specifier, it
indicates that the resulting string must contain at least the specified
number of digits; if the value has fewer digits, the resulting string is
left-padded with zeros.
Conversion characters may be specified in uppercase as well as in
lowercase-both produce the same results.
For all floating-point formats, the actual characters used as decimal and
thousand separators are obtained from the DecimalSeparator and
ThousandSeparator global variables.
Index, width, and precision specifiers can be specified directly using
decimal digit string (for example "%10d"), or indirectly using an asterisk
character (for example "%*.*f"). When using an asterisk, the next argument
in the argument list (which must be an integer value) becomes the value that
is actually used. For example,
TVarRec args[3] = {8,2,123.456};
Format("%*.*f", args, 2);
is the same as
TVarRec args[1] = {123.456};
Format("%8.2f", args, 0);
A width specifier sets the minimum field width for a conversion. If the
resulting string is shorter than the minimum field width, it is padded with
blanks to increase the field width. The default is to right-justify the
result by adding blanks in front of the value, but if the format specifier
contains a left-justification indicator (a "-" character preceding the width
specifier), the result is left-justified by adding blanks after the value.
An index specifier sets the current argument list index to the specified
value. The index of the first argument in the argument list is 0. Using
index specifiers, it is possible to format the same argument multiple times.
For example
TVarRec args[2] = {10, 20};
Format('%d %d %0:d %1:d', args, 1);
produces the string '10 20 10 20'.
Note: Setting the index specifier affects all subsequent formatting. That
is,
TVarRec args[4] = {1, 2, 3, 4};
Format('%d %d %d %0:d %d', args, 3);
returns '1 2 3 1 2', not '1 2 3 1 4'. To get the latter result, you have
must use
TVarRec args[4] = {1, 2, 3, 4};
Format('%d %d %d %0:d %3:d', args, 3);
-----
In addition to that, here is the documentation for the ARRAYOFCONST() and
OPENARRAY() macros, which are useful when calling Format():
---
ARRAYOFCONST macro
Assembles a set of values into a TVarRec array and the index of the last
element.
Header
sysopen.h
Category
Object Pascal emulation
#define ARRAYOFCONST(values) OpenArray<TVarRec>values,
OpenArrayCount<TVarRec>values.GetHigh()
Description
In many VCL parameter lists, a TVarRec object is required, followed by an
integer giving the index of the last TVarRec element. The ARRAYOFCONST macro
creates both parameters from a comma-separated list of values. For example,
the following code constructs a two-element TVarRec object and passes it to
the Format function.
Format("page %d of %d", ARRAYOFCONST(page, pages));
For a more general array creation macro, see OPENARRAY.
The two values created by ARRAYOFCONST are together equivalent to an Object
Pascal array of const value.
-----
OPENARRAY macro
Assembles a set of values into a TVarRec array and the index of the last
element.
Header
sysopen.h
Category
Object Pascal emulation
#define OPENARRAY(type, values) OpenArray<type>values,
OpenArrayCount<type>values.GetHigh()
Description
In some VCL parameter lists, an open array object is required, followed by
an integer giving the index of the last open array element. The OPENARRAY
macro creates both parameters from a comma-separated list, consisting of a
type followed by a series of values. This is similar to the ARRAYOFCONST
macro, except that OPENARRAY works with any array type. For example, the
following code constructs a Variant consisting of a two-integer variant
array.
Variant MyVariant(OPENARRAY(int, (0, 5)), varInteger);
The two values created by OPENARRAY are together equivalent to an Object
Pascal array of value.
Gambit