c语言string.h中常用的字符串操作函数
2016-10-13 15:42
357 查看
//根据指定字符切分字符串char *strtok(char *str1, char *str2); char input[26] = "I,am,a,boy"; char *p; p = strtok(input, ","); while(p) { printf("%s\n", p); p = strtok(NULL, ","); } //字符串反转char *strrev(char *str); char forward[] = "string"; printf("Before strrev(): %s\n", forward); strrev(forward); printf("After strrev(): %s\n", forward); //字符串中大小写转换,小写变大写:char *strupr(char *str);大写变小写:char *strlwr(char *str); char str[30] = "abcdefghijklmnopqrstuvwxyz"; strupr(str); printf(str); strlwr(str); printf(str); //在一个串中查找给定字符的第一个匹配之处char *strchr(char *str, char c); char str[22]="This is a string"; char* ptr=strchr(str, 'i'); if (ptr) printf(ptr); //在一个串中查找给定字符的最后一个匹配之处char *strrchr(char *str, char c); char str[22]="This is a string"; char* ptr=strrchr(str, 'i'); if (ptr) printf(ptr); //在串中查找指定字符串的第一次出现char *strstr(char *str1, char *str2); char str[22]="This is a string"; char* ptr=strstr(str,"is"); if (ptr) printf(ptr); //将字符串转换为double型值double strtod(char *str, char **endptr); //提取字符串中的小数 char str[52]="string89.23string0.896string4.56string"; char* ptr=str; int i=0; double nums[100]; while(*ptr!=0) { if(*ptr>='0' && *ptr<='9') nums[i++]=strtod(ptr,&ptr); ptr++; } for(int j=0;j='0' && *ptr<='9') nums[i++]=strtol(ptr,&ptr,10); ptr++; } for(int j=0;j[i][/i]
相关文章推荐
- WinCE下的非常用字符串操作函数
- PHP 常用字符串操作 函数
- PHP开发中常用的字符串操作函数
- mysql常用字符串操作函数大全,以及实例
- 字符串操作常用函数
- WinCE下的非常用字符串操作函数
- PHP字符串(1):常用字符串操作函数汇总
- 驱动开发 常用字符串操作函数
- PHP开发中常用的字符串操作函数
- mysql常用字符串操作函数大全,以及实例
- php 常用函数总结(数组,字符串,时间,文件操作)
- WinCE下的非常用字符串操作函数
- WinCE下的非常用字符串操作函数
- WinCE下的非常用字符串操作函数
- 字符串操作常用函数
- WinCE下的非常用字符串操作函数
- Linux下常用C语言字符串操作函数
- 基于php常用函数总结(数组,字符串,时间,文件操作)
- MYSQL字符串操作常用函数
- 常用C语言字符串操作函数