Replaces a character or substring with another.
int Replace( PCXSTR pszOld, PCXSTR pszNew ); int Replace( XCHAR chOld, XCHAR chNew );
- A pointer to a string containing the character to be replaced by pszNew.
- A pointer to a string containing the character replacing pszOld.
- The character to be replaced by chNew.
- The character replacing chOld.
The number of replaced instances of the character or substring. Zero if the string is not changed.
This function replaces instances of the specified character or substring with instances of the new character or substring.
The string may grow or shrink as a result of the replacement; that is, pszNew and pszOld do not have to be equal in length. The function performs a case-sensitive match.
The following example demonstrates the use of CStringT::Replace.
//typedef CStringT< TCHAR, StrTraitATL< TCHAR > > CAtlString; CAtlString strBang(_T("Everybody likes field hockey")); int n = strBang.Replace(_T("field hockey"), _T("soccer")); _ASSERT(n == 1);