Re: Trimming whitespaces
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Thu, 23 Jun 2005 16:53:49 GMT
john_g83@xxxxxxxxxxx wrote:
>
> have a bit of c code that is ment to take a string (that may or
> may not have spaces before or after the string) i.e. " stuff ",
> and trims off the whitespace before and after.
> Code:
>
> char *trim (char *str, char ch)
Untested:
char *trim(char *s, char ch)
{
char *p;
if (s && *s && ch) { /* avoid evil cases */
while (ch == *s) s++; /* trims leading. */
p = s; /* must be advanced over entry */
while (*p) p++; /* find end of string */
p-- /* last char in string */
while ((p > s) && (ch == *p)) p--;
*p = '\0';
}
return s; /* ok in evil cases */
}
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
.
- Follow-Ups:
- Re: Trimming whitespaces
- From: Chris Torek
- Re: Trimming whitespaces
- References:
- Trimming whitespaces
- From: john_g83
- Trimming whitespaces
- Prev by Date: Re: What does it mean ?
- Next by Date: Re: Portability
- Previous by thread: Re: Trimming whitespaces
- Next by thread: Re: Trimming whitespaces
- Index(es):
Relevant Pages
|