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 that contains the target characters to be trimmed. All leading and trailing occurrences of characters in pszTarget will be trimmed from the CStringT object.

Return Value

Returns the trimmed string.

Remarks

Removes all leading and trailing occurrences of one of these:

  • The character specified by chTarget.

  • All characters in the string specified by pszTargets.

  • Whitespace.

Example

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

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

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

Remarks

The output from this example is as follows.

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

After : "Soccer is best, but hockey is quicker"

Requirements

Header: cstringt.h

See Also

Reference

CStringT Class

CStringT::TrimLeft

CStringT::TrimRight

Other Resources

CStringT Members

Change History

Date

History

Reason

July 2009

Modified the example code output wording.

Content bug fix.