Sort string-related functions

Source: Internet
Author: User
String-related functions in string. h
Category by function:

String connection:
Strcat: char * strcat (char * destination, const char * Source );

Strncat: char * strcat (char * destination, const char * Source, size_t num );

Cat means catenate, and connection means.

Strncp is a secure version of strcat, which can prevent cross-border attacks.

From the definition, we can see that the string with const is connected to a string without Const.

Character/string SEARCH:
Strchr: char * strchr (const char * STR, int character); char * strchr (char * STR, int character );

Returns a pointer pointing to the character at the end of the string.

Because '\ 0' is also a part of the string, this function can also find the Terminator.

CHR indicates character.

Strrchr: char * strchr (const char * STR, int character); char * strchr (char * STR, int character );

The last position that appears. 'R' should mean right, that is, right-based search.

Strpbrk: const char * strpbrk (const char * str1, const char * str2); char * strpbrk (char * str1, const char * str2 );

Search for the position where any character in str2 appears for the first time in str1, and return the string from the entire position to the last character in str1. Does not contain the Terminator.

Strcspns: size_t strcspns (const char * str1, const char * str2 );

The returned result is the first occurrence of any character in str2. The search contains the null Terminator, so the function can return the str1 string length without any matching.

Strstr: const char * strstr (const char * str1, const char * str2); char * strstr (char * str1, const char * str2 );

Match the complete string

String comparison:
Strcmp: int strcmp (const char * str1, const char * str2 );

Strncmp: int strcmp (const char * str1, const char * str2, size_t num );

Strcoll: int strcoll (const char * str1, const char * str2 );

Compare str1 and str2 according to lc_coliate.

String Copy:
Strcpy: char * strcpy (char * destination, const char * Source );

Strncpy: char * strcpy (char * destination, const char * Source, size_t num );

Copy source to destination. '\ 0' indicates that copy is stopped.

Obtain the string length:
Strlen: size_t strlen (const char * Str );

Split string:
Strtok: char * strtok (char * STR, const char * delimiters );

Tok indicates the token, which is used to split STR according to delimiter.

Sort string-related functions

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.