Поделиться через


CStringT::Replace

Replaces a character or substring with another.

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

Параметры

  • 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.

Возвращаемое значение

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

Пример

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

Требования

Header: cstringt.h

См. также

Основные понятия

CStringT Class

CStringT Members