Remove the space at both ends of the string trimSpace

Source: Internet
Author: User

Remove the space at both ends of the string trimSpace
There is a string with n spaces ("abcdefgdddd") at the beginning or end. To remove the leading and trailing spaces, a new string is returned.

Int trimSpace (char * bufscr, char * bufdes) {int I = 0; char * p = bufscr; // pointer variable, in order not to modify the incoming pointer int len = strlen (bufscr); int j = len-1; int count; // non-null character length int ret = 0; // first determine whether the passed pointer is NULL if (bufscr = NULL | bufdes = NULL) {ret =-1; printf ("func trimSpace err % d :", ret); return ret;} while (isspace (p [I]) & p [I]! = '\ 0') {I ++;} while (isspace (p [j]) & j> 0) {j --;} count = j-I + 1; memcpy (bufdes, p + I, count); // You must note that the difference between a string array and a string is that the string array ends with multiple \ 0' characters '. Bufdes [count] = '\ 0'; return ret ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.