Freigeben über


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 can 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

// typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;

CAtlString strBang(_T("Everybody likes epee fencing"));
int n = strBang.Replace(_T("epee"), _T("foil"));
ASSERT(n == 1);   

Requirements

Header: cstringt.h

See Also

Concepts

CStringT Class

CStringT Members