C Language Development Kit/Snippets/String/Trim

From OptiWiki

Jump to: navigation, search
Description Removes the specific leading and trailing characters from a string.
Syntax
char *Trim( char *pszSource, char removeChar );
Arguments
char *pszSource
The source input string where the leading and trailing characters need be be remove from.
char removeChar
The specific key that is used to remove from the source input string.
Returns A pointer to the changed source input string.
Remarks The source input string is changed by this function.
Example
#include "lib.h"
#include <stdio.h>
#include "input.h"     //Holds the input functions
#include "strfunc.h"   //Holds the string manipulation functions
 
void main( void )
{
    static char dummy[ 21 ];
 
    for(;;)
    {
        strcpy( dummy, "      123456      ");
        printf("\forg:|%s|,", dummy );
        printf("new:|%s|\n", Trim( dummy, ' ' ));
 
        printf("\npress a key");
        WaitForKey();
    }
}


Views
Personal tools