Share via


AfxFormatString2

Substitutes the string pointed to by lpsz1 for any instances of the characters "%1", and the string pointed to by lpsz2 for any instances of the characters "%2", in the template string resource identified by nIDS.

void AfxFormatString2( 
   CString& rString, 
   UINT nIDS, 
   LPCTSTR lpsz1, 
   LPCTSTR lpsz2  
);

Parameters

  • rString
    A reference to the CString that will contain the resultant string after the substitution is performed.

  • nIDS
    The string table ID of the template string on which the substitution will be performed.

  • lpsz1
    A string that will replace the format characters "%1" in the template string.

  • lpsz2
    A string that will replace the format characters "%2" in the template string.

Remarks

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.

Example

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_FILENOTFOUND2, pszFileName, pszDirectory);
   // In the previous call, substitute the actual file and directory  
   // names into the message string
   AfxMessageBox(strMessage);  // Display the error message
}

Requirements

Header: afxwin.h

See Also

Reference

AfxFormatString1

Concepts

MFC Macros and Globals