Compartilhar via


CStringT::Insert

Inserts a single character or a substring at the given index within the string.

int Insert(
   int iIndex,
   PCXSTR psz
);
int Insert(
   int iIndex,
   XCHAR ch
);

Parameters

  • iIndex
    The index of the character before which the insertion will take place.

  • psz
    A pointer to the substring to be inserted.

  • ch
    The character to be inserted.

Return Value

The length of the changed string.

Remarks

The iIndex parameter identifies the first character that will be moved to make room for the character or substring. If nIndex is zero, the insertion will occur before the entire string. If nIndex is higher than the length of the string, the function will concatenate the present string and the new material provided by either ch or psz.

Example

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

CAtlString str(_T("SoccerBest"));
int n = str.Insert(6, _T("is "));
ASSERT(n == str.GetLength());
_tprintf_s(_T("1: %s\n"), (LPCTSTR) str);

n = str.Insert(6, _T(' '));
ASSERT(n == str.GetLength());
_tprintf_s(_T("2: %s\n"), (LPCTSTR) str);

n = str.Insert(55, _T('!'));
ASSERT(n == str.GetLength());
_tprintf_s(_T("3: %s\n"), (LPCTSTR) str);

Requirements

Header: cstringt.h

See Also

Reference

CStringT Class