This documentation is archived and is not being maintained.


Loads the specified string resource and substitutes the characters "%1" and "%2" for the strings pointed to by lpsz1 and lpsz2.

void AfxFormatString2(
   CString& rString,
   LPCTSTR lpsz1,
   LPCTSTR lpsz2 


A reference to the CString that will contain the resultant string after the substitution is performed.
The string table ID of the template string on which the substitution will be performed.
A string that will replace the format characters "%1" in the template string.
A string that will replace the format characters "%2" in the template string.


The newly formed string is stored in rString. For example, if the string in the string table is "File %1 not found in directory %2", lpsz1 points to "MYFILE.TXT", and lpsz2 points to "C:\MYDIR", then rString will contain the string "File MYFILE.TXT not found in directory C:\MYDIR"

If the format characters "%1" or "%2" appear in the string more than once, multiple substitutions will be made. They do not have to be in numerical order.


void DisplayFileNotFoundMessage( LPCTSTR pszFileName, LPCTSTR pszDirectory )
   CString strMessage;

   // The IDS_FILENOTFOUND string resource contains "Error: File %1 not 
   // found in directory %2"
   AfxFormatString2( strMessage, IDS_FIlENOTFOUND, pszFileName, pszDirectory );
   // In the previous call, substitute the actual file and directory 
   // names into the message string
   AfxMessageBox( strMessage );  // Display the error message

See Also

MFC Macros and Globals | AfxFormatString1