Find a String prefix
size_t strspn (char const *str,char const *group)
size_t strcspn (char const *str,char const *group)
STRSPN returns the number of characters in the start of STR that match any character in the group
Strcspn He makes a technique of matching characters in the beginning part of the STR string with any character in the group
Finds the location of the last occurrence of the specified string in a string
Strrstr
#include <stdio.h> #include <assert.h> #include <string.h> #include <stdlib.h>char *strrstr ( Const CHAR*STR1, char *str2) {assert (STR1); assert (STR2); char *last = Null;char *cur = strstr (str1, str2); while (cur! = NULL {last = Cur;//last is saved from the final address of the string not NULL cur = strstr (cur+1, str2);} Return last;//returns the last occurrence of the position}int main () {char *p = "Abcdefgabcdef"; char *q = "Cdef"; char *ret = STRRSTR (p, Q);p rintf ("%s\n", R ET); System ("pause"); return 0;}
Strtok it isolates separate parts called tokens (tokens) from the string and discards the delimiter
Char *strtok (char *str,char const *SEP)
The Sep parameter is a string that defines the character set of the delimiter
If the first argument of strtok is not NULL, the function will find the first token of the string, strtok it at the same time as the position of the string
If the first parameter of the strtok is NULL, the function starts from the saved position in the same string and looks for the next tag as before
Strtok#include<stdio.h> #include <string.h>int main () {char *p = "193.168.0.1"; char arr[20];strcpy (arr, p ); char *token = Null;/*char *token = strtok (arr, "."); printf ("%s\n", token), while (token! = NULL) {token = Strtok (null, "."); if (token!=null) printf ("%s\n", token);} */for (token = strtok (arr, "."); Token! = Null;token = Strtok (NULL, ".")) {printf ("%s\n", token);} System ("pause"); return 0;} //
Strerror
char *strerror (int error_number)
Open File//errno#include<stdio.h> #include <errno.h>int main () {File *PF = fopen ("C:\\codetest.text", "R"); if (PF = = NULL) {printf ("error:%s\n", Strerror (errno));//Print the appropriate error message//If the correct output no error//if the file name does not exist, then output "error:no such file or dictory" Wait for printf ("Open File error\n");} Systme ("Pasue"); return 0;} Error description Information//char *strerror (int error_number);//returns error message with error code//strerror (errno)//ERRNO.H error code defined in header file errno when an error occurs, The error code is placed in the current error code//
Memory operations
The string function has limitations when the content to be manipulated has "\"
void *memcpy (void *dst,void const *src,zise_t length)
void *memmove (void *dst,void const *src,zise_t length)
void *memcmp (void *a,void const *b,zise_t length)
Voif *memchr (void *a,int ch,zise_t length)
class to a space
Memset
void memset (void *dest,int c,size_t count)
This article is from the "incomparable Warm yang" blog, please be sure to keep this source http://10797127.blog.51cto.com/10787127/1722962
Advanced String Functions