The usage of trim (), trimend (), and trimstart () in C.

Source: Internet
Author: User

These three methods are used to delete certain characters that appear at the beginning and end of a string. Trim () deletes spaces in the header and tail of a string. The deletion process is from the outside to the inner until a non-space character is encountered, therefore, no matter how many consecutive spaces exist before and after it is deleted. Trimstart () only deletes spaces in the string header. Trimend () only removes spaces at the end of the string.

If these three functions carry the parameters of the struct array, they are to delete any character that appears in the struct array. For example, trim ("ABCD ". tochararray () is to delete the, B, C, or D characters in the header and tail of a string, the deletion process ends until it encounters a character that is neither a nor B nor C nor D.
The most common misunderstanding here is that the "ABCD" string is deleted. For example:
String S = "from dual Union all ";
S = S. Trim (). trimend ("Union all". tochararray ());
Some people may think that the final result of S is "from dual", but the real result is "from D ". Note that the delete object executed in this writing method is any character in the character array, rather than a string consisting of these characters!

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.