Return to Snippet

Revision: 60225
at October 26, 2012 05:03 by pjaicher


Initial Code
char *trim(char *str)
{
	char *out = str;
	out = trim_left(out);
	out = trim_right(out);
	return out;
}

char *trim_left(char *str)
{
     if(str[0] != ' ' || str[0] == '\0') return str;
     return trim_left(str++);
}

char *trim_right(char *str)
{
	int len = strlen(str) - 1;
	if(len == 0 || str[len] != ' ') return str;
	str[strlen(str)-1] = '\0';
	return trim_right(str);
}

Initial URL

                                

Initial Description
These functions will allow you to trim left and right on a string

Initial Title
Trim in ANSII C

Initial Tags

                                

Initial Language
C