CString::Insert

int Insert( int nIndex, TCHAR ch )
throw( CMemoryException );

int Insert( int nIndex, LPCTSTR pstr )
throw( CMemoryException );

Return Value

The length of the changed string.

Parameters

nIndex

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

ch

The character to be inserted.

pstr

A pointer to the substring to be inserted.

Remarks

Call this member function to insert a single character or a substring at the given index within the string. The nIndex 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 pstr.

Example

//The following example demonstrates the use of CString::Insert.
   CString str("HockeyBest");
   int n = str.Insert(6, "is ");
   ASSERT(n == str.GetLength());
   printf("1: %s\n", (LPCTSTR) str);

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

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

//this code generates these lines of output:

1: Hockeyis Best
2: Hockey is Best
3: Hockey is Best!

CString OverviewClass MembersHierarchy Chart

See Also   CString::Delete, CString::operator +