Always do is the microcontroller-related program design, so the program is more inclined to the bottom, the operation of the string is limited to the display of the LCD screen, etc., want to improve the level of the string operation, rather than clumsy array substitution, and so on, look at the post found that the C language string operation function is so rich and practical, This record is ready for use.
the strlen (): string length calculation function
Application Examples:
1#include <stdio.h>2#include <string.h>3 4 CharTextbuff[] ="hello_my_friend!";5 6 intMainvoid)7 {8printf"the length of the Textbuff is:%d\r\n", strlen (Textbuff)); 9}
No.2 strcpy (): string copy function
Application Examples:
1#include <stdio.h>2#include <string.h>3 4 Char*textbuff="hello_my_friend!";5 Charrevbuff[ -];6 7 intMainvoid)8 {9 strcpy (revbuff,textbuff);Tenprintf"revbuff:%s\r\n", Revbuff); One}
No.3 strcat (): string concatenation function
Application Examples:
1#include <stdio.h>2#include <string.h>3 4 intMainvoid)5 {6 Char*Textbuff;7 Char*a="IamA";8 Char*b="iamb";9 Char*c="IAMC"; Ten strcat (textbuff,a); One strcat (textbuff,b); A strcat (TEXTBUFF,C); -printf"the length of the Textbuff is:%d\n", strlen (Textbuff)); -printf"%s\n", Textbuff); the}
No.4 STRCHR (): String lookup (first occurrence position)
Application Examples:
1#include <stdio.h>2#include <string.h>3 4 intMainvoid)5 {6 Chartext[Ten]="Wearetheab";7 Char*Ptr;8 CharA='a';9 TenPtr=STRCHR (text,a); Oneprintf"the position of a is in the first%d position of text \ n", ptr-text+1); A}
No.5 strcmp (): string comparison function
Application Examples:
1#include <stdio.h>2#include <string.h>3 4 intMainvoid)5 {6 Char*a="hello!";7 Char*b="hello!";8 Charnum=0;9num=strcmp (A, b);Ten if(num==0) One { Aprintf"two arrays equal \ n"); - } - Else the { -printf"two arrays not equal \ n"); - } -}
Common string manipulation functions for C language (i)