Export (0) Print
Expand All

CStringT::Replace

Replaces a character or substring with another.

int Replace(
   PCXSTR pszOld,
   PCXSTR pszNew
);
int Replace(
   XCHAR chOld,
   XCHAR chNew
);

Parameters

pszOld
A pointer to a string containing the character to be replaced by pszNew.
pszNew
A pointer to a string containing the character replacing pszOld.
chOld
The character to be replaced by chNew.
chNew
The character replacing chOld.

Return Value

The number of replaced instances of the character or substring. Zero if the string is not changed.

Remarks

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.

Example

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);

See Also

CStringT Overview | Class Members

Show:
© 2014 Microsoft