Export (0) Print
Expand All

CStringT::Trim 

Trims all leading and trailing whitespace from the string.


CStringT& Trim(
   XCHAR chTarget 
);
CStringT& Trim(
   PCXSTR pszTargets 
);
CStringT& Trim( );

Parameters

chTarget

The target character to be trimmed.

pszTargets

A pointer to a string containing the target characters to be trimmed. All leading and trailing occurrences of characters in pszTarget will be trimmed from the CStringT object.

Returns the trimmed string.

Removes all leading and trailing occurrences of one of the following:

  • The character specified by chTarget.

  • All characters found in the string specified by pszTargets.

  • Whitespace.

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

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

    CAtlString str;
    str = _T("******Soccer is best, but liquor is quicker!?!?!?!?!");

    _tprintf_s(_T("Before: \"%s\"\n"), (LPCTSTR) str);
    _tprintf_s(_T("After : \"%s\"\n"), (LPCTSTR) str.Trim(_T("?!*")));

   return 0;
}

Output

Before: "******Soccer is best, but liquor is quicker!?!?!?!?!"
After : "Soccer is best, but liquor is quicker"

Community Additions

ADD
Show:
© 2014 Microsoft