一常用到的C字符串库函数:
strok函数:char *strtok(char *str, const char *delim)在AT命令,JSON等场合很有用,类似功能sscanf函数。
以delim为分隔符分割str,如果没检索到返回NULL,否则返回被分解的第一个子字符串;后面再用NULL作为第一个参数继续分解直到结束。比如:
1 #include <stdio.h> 2 3 #include <stdlib.h> 4 5 #include <string.h> 6 7 int main(void) 8 9 { 10 11 char str[] ="Apple,Pear,Potato,11"; 12 13 char* tokens = strtok (str,","); 14 15 //iterate over tokens.. . 16 17 while (tokens!= NULL) 18 19 { 20 21 printf ("%s",tokens); 22 23 tokens = strtok (NULL,","); 24 25 } 26 27 return 0; 28 29 }
strstr