Export (0) Print
Expand All

CStringT::Delete 

Deletes a character or characters from a string starting with the character at the given index.


int Delete(
   int iIndex,
   int nCount = 1
);

Parameters

iIndex

The zero-based index of the first character in the CStringT object to delete.

nCount

The number of characters to be removed.

The length of the changed string.

If nCount is longer than the string, the remainder of the string will be removed.

// cstringt_delete.cpp
#include <atlstr.h>
#include <stdio.h>

int main( int argc, char* argv[] )
{
    //typedef CStringT< TCHAR, StrTraitATL< TCHAR > > CAtlString;

    CAtlString str( "Soccer is best, but liquor is quicker!");
    printf_s("Before: %s\n", (LPCTSTR) str);

    int n = str.Delete(6, 3);
    printf_s("After: %s\n", (LPCTSTR) str);
    _ASSERT(n == str.GetLength());

    return 0;
}

Output

Before: Soccer is best, but liquor is quicker!
After: Soccer best, but liquor is quicker!

Community Additions

ADD
Show:
© 2015 Microsoft