Exporter (0) Imprimer
Développer tout
Développer Réduire
Cet article a fait l'objet d'une traduction automatique. Déplacez votre pointeur sur les phrases de l'article pour voir la version originale de ce texte. Informations supplémentaires.


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

En-tête : afxwin.h

Ajouts de la communauté

© 2014 Microsoft