{* *}
code teams

Trim Whitespace



/********************************************************************
* Function: TrimWhiteSpace
*
* Author: Stefan Willmert
*
* Description: Uses the isspace function to trim leading and trailing
*     white space from a string
*
* Comments: Assumes a string starting with '#' is a comment
*
* Example:
*     char szIn[100];
*     strcpy(szIn, "   test string   ");
*     char *pOut = TrimWhiteSpace(szIn);
*
*********************************************************************/
char *TrimWhiteSpace(char *strIn)
{
    char *strOut;
    if (strIn == NULL)
        return NULL;

    strOut = strIn + strlen( strIn );

    /* clip off trailing and leading white space
    */
    strOut--;
    while( isspace( *strOut ) && strOut >= strIn )
        *strOut-- = '\0';
    strOut = strIn;
    while( isspace( *strOut ))
        strOut++;
    if( 0 == strlen( strOut ))
        return NULL;

    if (strOut[0] == '#')
        return NULL;

    return strOut;

}