去除字符串中首尾的空格

<textarea cols="50" rows="15" name="code" class="cpp">void change(char *p) { int nLen = strlen(p); int nFirst = 0; int nLast = 0; for (int i=0; i!=nLen; ++i) { if (' ' != *(p+i)) { nFirst = i; break; } } for (int i=nLen-1; i&gt;=0; --i) { if (' ' != *(p + i)) { nLast = i; break; } } int nPos = 0; if (nFirst == nPos) { nPos = nLast+1; } else { for (int i=nFirst; i&lt;=nLast; ++i) { *(p+nPos++) = *(p+i); } } *(p+nPos) = '/0'; }</textarea>

 

你可能感兴趣的:(去除字符串中首尾的空格)