Tuesday, February 24, 2015

Using StrTrim function

Courtesy msdn.microsoft.com

Removes specified leading and trailing characters from a string.

https://msdn.microsoft.com/en-us/library/windows/desktop/bb773454(v=vs.85).aspx

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, pszreceives 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.

 #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

No comments:

Post a Comment