Learning data structure (7)-string

1. What is string?

Strings are called strings for short. A string is a finite sequence consisting of 0, 1, and multiple characters. The sub-sequence composed of any continuous character in the string is called the sub-string of the string.

2. C++ string processing library

The library function name is <string>.

(1) Copy function

char* strcpy(char *strDestinnation,const char* strSource);

strSource is the source string, strDestinnation is the target string, and returns the target string. Note: This function does not check the spatial completeness of the function.

(2) Partial copy function

int strncpy(char *strDest,const char* strSource,size_t count);

strSource is the source string, strDest is the target string, and count is the number of copies starting from the first character. Note: This function does not check the spatial completeness of the function.

(3) Connection function

char *strncat(char* strDest,const char* strSource,char c);

strSource is the source string, strDest is the target string, and returns the result string. Note: The function does not detect the upper limit.

(4) Part of the connection function

char* strncat(char* strDest,const char* strSource,size_t count);

Add the first count characters in strSource to the tail of strDest, and add a terminating character at the end, and return the result string.

(5) The function to search for the first occurrence of the specified character

char* strchr(const char* str,char c)

Find c in str, and if successful, return the address of the first character; otherwise, the operation fails and NULL is returned.

(6) The function to search for the last occurrence of the specified character

char* strrchr(const char* str,char c);

Find c in str, and if successful, return the address of the last character; otherwise, the operation fails and NULL is returned.

(7) The function to search for the first occurrence of the specified string

size_t strcspn(const char* string,cosnt char* strCharSet);

Returns the subscript value of the first character in the string belonging to strCharSet.

(8) Length function

size_t strlen(const char* string);

Returns the number of characters in string.

(9) Comparison function

int strcmp(const char* string1,const char* string)

Compare the size of string1 and string2, if string1=string2, it will return 0, if string1>string2, it will return 1, and if string1<string2, it will return -1.

(10) Partial comparison function

int strncmp(const char* string1,const char* string,size_t count);

Compare the size of the first count characters of string1 and string2. If string1=string2, it will return 0, if string1>string2, it will return 1, and if string1<string2, it will return -1.

(11) Find the first public character function

char* strpbrk(const char* str,const char* strCharSet);

Returns the first pointer of any common character in str and strCharSet, or NULL if there is no common character.

(12) Find the first public substring function

char* strstr(const char* str,const char* strCharSet);

Returns the pointer of the first character that strCharSet matches for the first time in str, or NULL if there is no substring.

3. Storage method

(1) The fixed-length sequential storage representation of the string: similar to the sequential storage structure of a linear table, that is, it is implemented with a fixed-length character array, and the storage space is statically allocated at compile time.

(2) Heap allocation storage representation of strings: The string-valued character sequence is still stored in a group of consecutive address storage units, but the storage space is dynamically allocated during the execution of the program.

(3) Block chain storage of string means: store nodes in a set of discontinuous storage units.

Guess you like

Origin blog.csdn.net/qq_35789421/article/details/113777084