void Format( LPCTSTR lpszFormat, ... );
void Format( UINT nFormatID, ... );
Parameters
lpszFormat
A format-control string.
nFormatID
The string resource identifier that contains the format-control string.
Remarks
Call this member function to write formatted data to a CString in the same way that sprintf formats data into a C-style character array. This function formats and stores a series of characters and values in the CString. Each optional argument (if any) is converted and output according to the corresponding format specification in lpszFormat or from the string resource identified by nFormatID.
The call will fail if the string object itself is offered as a parameter to Format. For example, the following code:
CString str = "Some Data";
str.Format("%s%d", str, 123); // Attention: str is also used in the parameter list.
will cause unpredictable results.
When you pass a character string as an optional argument, you must cast it explicitly as LPCTSTR. The format has the same form and function as the format argument for the printf function. (For a description of the format and arguments, see printf in the Run-Time Library Reference.) A null character is appended to the end of the characters written.
For more information, see sprintf in the Run-Time Library Reference.
CString Overview | Class Members | Hierarchy Chart
See Also CString::GetBuffer, CString::FormatV