String library functions ----------- summarize some common string processing functions.

Source: Internet
Author: User

String library functions ----------- summarize some common string processing functions.

Header file: # include

 

First place

Char * strstr (char * dest, char * need );

Locate the position where the need string appears from the dest string. If the end character is not compared, NULL is not found and the position where the need string is returned is found.

 

Second place

Char * strcat (char * dest, char * src );

Char * strncat (char * dest, char * src, size_t n );

Add the string pointed to by src to the end of the dest and overwrite the '\ 0' at the end of the string. Return the pointer to the dest. strncat () has one more parameter, is to copy n characters in src. Note: Make sure that the dest has enough space to receive the src!

 

Third place

Char * strcpy (char * dest, char * src );

Char * strncpy (char * dest, char * src, size_t n );

Copy the content in the src string to the dest, and copy the end mark of the string together. Strncpy () is also a parameter that specifies the number of copied bytes.

 

Fourth place

Size_t strspn (const char * s, const char * accept );

Size_t strcspn (const char * s, const char * reject );

The strspn function returns the number of characters in the S string that belong to the string's accept from the beginning. In other words, if the strspn function returns n, it indicates that n characters in string S are all characters in string accept from the beginning. In contrast, the strcspn function returns the number of characters in the S string from the beginning that do not belong to the characters in the string accept.

 

Fifth place

Char * strchr (const char * s, char c );

Char * strrchr (const char * s, char c );

The former is the pointer to the position where the character in c appears for the first time in string S, and the latter is the pointer to the position where the character in c appears for the last time in string S.

 

Sixth

Char * strdup (const char * s );

Char * strndup (const char * s, size_t n );

Copy the string to the new address, and return the pointer of the new address. The latter adds up to n characters for copying. If the string s exactly contains n characters, the terminator '\ 0' is automatically added.

 

 

Related Article

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.