Return the index of the first char not in trimchars, or if none, of the trailing nul in the string. Note that if you trimleft and trimright a string of spaces, the two indicies would cross, so be careful. See trimboth.
| 52 | // Return the index of the first char not in trimchars, or if none, of the trailing nul in the string. |
| 53 | // Note that if you trimleft and trimright a string of spaces, the two indicies would cross, so be careful. See trimboth. |
| 54 | size_t trimleftn(const char *startp, size_t startpos/*=0*/, const char *trimchars /*=" \t\r\n"*/) |
| 55 | { |
| 56 | while (startp[startpos] && strchr(trimchars,startp[startpos])) { startpos++; } |
| 57 | return startpos; |
| 58 | } |
| 59 | |
| 60 | // Trim both ends of a string. |
| 61 | string trimboth(string input, const char *trimchars /*=" \t\r\n"*/) |