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

void AfxFormatString1(
   CString& rString,
   LPCTSTR lpsz1 


A reference to a CString object that will contain the resultant string after the substitution is performed.


The resource 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.

The newly formed string is stored in rString. For example, if the string in the string table is "File %1 not found", and lpsz1 is equal to "C:\MYFILE.TXT", then rString will contain the string "File C:\MYFILE.TXT not found". This function is useful for formatting strings sent to message boxes and other windows.

If the format characters "%1" appear in the string more than once, multiple substitutions will be made.

void DisplayFileNotFoundMessage(LPCTSTR pszFileName)
   CString strMessage;

   // The IDS_FILENOTFOUND string resource contains "Error: File %1 not found"
   AfxFormatString1(strMessage, IDS_FILENOTFOUND, pszFileName);
   // In the previous call, substitute the actual file name for the
   // %1 placeholder
   AfxMessageBox(strMessage);  // Display the error message

Header: afxwin.h

Community Additions