Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

StrTrim function

Removes specified leading and trailing characters from a string.

Syntax


BOOL StrTrim(
  _Inout_ PTSTR  psz,
  _In_    PCTSTR pszTrimChars
);

Parameters

psz [in, out]

Type: PTSTR

A pointer to the null-terminated string to be trimmed. When this function returns successfully, psz receives the trimmed string.

pszTrimChars [in]

Type: PCTSTR

A pointer to a null-terminated string that contains the characters to trim from psz.

Return value

Type: BOOL

TRUE if any characters were removed; otherwise, FALSE.

Examples


#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"

void main(void)
{
    //String one
    TCHAR buffer[ ] = TEXT("_!ABCDEFG#");
    TCHAR trim[ ] = TEXT("#A!_\0");

    cout  <<  "The string before calling StrTrim: ";
    cout  <<  buffer;
    cout  <<  "\n";

    StrTrim(buffer, trim);

    cout  <<  "The string after calling StrTrim: ";
    cout  <<  buffer;
    cout  <<  "\n";
}

OUTPUT:
- - - - - -
The string before calling StrTrim: _!ABCDEFG#
The string after calling StrTrim: BCDEFG

Requirements

Minimum supported client

Windows 2000 Professional, Windows XP [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Shlwapi.h

Library

Shlwapi.lib

DLL

Shlwapi.dll (version 4.71 or later)

Unicode and ANSI names

StrTrimW (Unicode) and StrTrimA (ANSI)

 

 

Community Additions

ADD
Show:
© 2015 Microsoft