C/C++字符串查找函数 <转>
来源:互联网 发布:火山移动编程下载 编辑:程序博客网 时间:2024/05/22 10:48
C/C++ string库(string.h)提供了几个字符串查找函数,如下:
memchr 在指定内存里定位给定字符
strchr 在指定字符串里定位给定字符
strcspn 返回在字符串str1里找到字符串str2里的任意一个字符之前已查找的字符数量
strrchr 在字符串里定位给定字符最后一次出现的位置
strpbrk 在字符串str1里定位字符串str2里任意一个首次出现的字符
strspn 返回字符串str1从开始字符到第一个不在str2中的字符个数
strstr 在字符串str1中定位字符串str2首次出现的位置
函数说明:
1、memchr
原型:const void * memchr ( const void * ptr, int value, size_t num);
void * memchr ( void * ptr, int value, size_t num);
参数:ptr,待查找的内存指针;
value,要查找的值;
num,内存大小。
说明:在ptr指向的内存中查找value,返回指向和value首次匹配的元素指针,如果没有找到,返回NULL指针。
2、strchr
原型:const char * strchr ( const char * str, int character);
char * strchr ( char * str, int character);
参数:str,待查找字符串指针;
character,要查找的值。
说明:在字符串str中查找character,返回指向和character首次匹配的元素指针,如果没有找到,返回NULL指针。
3、strcspn
原型:size_t strcspn ( const char * str1, const char * str2);
参数:str1,待查找的字符串指针;
str2,要查找的字符串指针。
说明:在str1中查找str2中的字符,返回找到str2中任意一个字符时已查找的字符个数。
4、strrchr
原型:const char * strrchr ( const char * str, int character);
char * strrchr ( char * str, int character);
参数:str,待查找的字符串指针;
character,要查找的值。
说明:在str中查找character,返回指向与character最后一次匹配的元素的指针,如果没有找到,返回NULL指针。
5、strpbrk
原型:const char * strpbrk (const char * str1, const char * str2);
char * strpbrk ( char * str1, const char * str2);
参数:在str1中查找str2中任意一个字符,返回指向与首次出现的str2中的任意一个字符匹配的元素的指针,如果没有找到,返回NULL指针。
6、strspn
原型:size_t strspn ( const char * str1, const char * str2);
参数:str1,待查找的字符串指针;
str2,要查找的字符串指针。
说明:从str1的第一个字符开始算起,直到出现一个不在str2中的字符为止,返回字符个数。
7、strstr
原型:const char * strstr ( const char * str1, cosnt char *str2);
char * strstr ( char * str1, const char * str2);
参数:str1,待查找的字符串指针;
str2,要查找的字符串指针。
memchr 在指定内存里定位给定字符
strchr 在指定字符串里定位给定字符
strcspn 返回在字符串str1里找到字符串str2里的任意一个字符之前已查找的字符数量
strrchr 在字符串里定位给定字符最后一次出现的位置
strpbrk 在字符串str1里定位字符串str2里任意一个首次出现的字符
strspn 返回字符串str1从开始字符到第一个不在str2中的字符个数
strstr 在字符串str1中定位字符串str2首次出现的位置
函数说明:
1、memchr
原型:const void * memchr ( const void * ptr, int value, size_t num);
void * memchr ( void * ptr, int value, size_t num);
参数:ptr,待查找的内存指针;
value,要查找的值;
num,内存大小。
说明:在ptr指向的内存中查找value,返回指向和value首次匹配的元素指针,如果没有找到,返回NULL指针。
2、strchr
原型:const char * strchr ( const char * str, int character);
char * strchr ( char * str, int character);
参数:str,待查找字符串指针;
character,要查找的值。
说明:在字符串str中查找character,返回指向和character首次匹配的元素指针,如果没有找到,返回NULL指针。
3、strcspn
原型:size_t strcspn ( const char * str1, const char * str2);
参数:str1,待查找的字符串指针;
str2,要查找的字符串指针。
说明:在str1中查找str2中的字符,返回找到str2中任意一个字符时已查找的字符个数。
4、strrchr
原型:const char * strrchr ( const char * str, int character);
char * strrchr ( char * str, int character);
参数:str,待查找的字符串指针;
character,要查找的值。
说明:在str中查找character,返回指向与character最后一次匹配的元素的指针,如果没有找到,返回NULL指针。
5、strpbrk
原型:const char * strpbrk (const char * str1, const char * str2);
char * strpbrk ( char * str1, const char * str2);
参数:在str1中查找str2中任意一个字符,返回指向与首次出现的str2中的任意一个字符匹配的元素的指针,如果没有找到,返回NULL指针。
6、strspn
原型:size_t strspn ( const char * str1, const char * str2);
参数:str1,待查找的字符串指针;
str2,要查找的字符串指针。
说明:从str1的第一个字符开始算起,直到出现一个不在str2中的字符为止,返回字符个数。
7、strstr
原型:const char * strstr ( const char * str1, cosnt char *str2);
char * strstr ( char * str1, const char * str2);
参数:str1,待查找的字符串指针;
str2,要查找的字符串指针。
说明:在str1中查找匹配str2的子串,并返回指向首次匹配时的第一个元素指针。如果没有找到,返回NULL指针。
http://blog.csdn.net/isgray/article/details/6853700
阅读全文
0 0
- C 字符串查找函数
- C 字符串查找函数
- C/C++字符串查找函数 <转>
- C语言字符串查找函数
- C/C++字符串查找函数
- C/C++字符串查找函数
- C/C++字符串查找函数
- C/C++字符串查找函数
- C/C++字符串查找函数
- C/C++字符串查找函数
- C/C++字符串查找函数
- C/C++字符串查找函数
- C/C++字符串查找函数
- C/C++字符串查找函数
- C语言版字符串查找函数,字符串中查找子串
- c实现的字符串查找函数
- C语言的字符串查找函数
- C字符串操作:查找字符串函数strstr()
- 下半年全屏大战 千元机将集体变脸
- Vs2013 中设置Pythonw
- js实现json和xml数据的解析方法
- 5. Longest Palindromic Substring
- CentOS 7 下编译gdal
- C/C++字符串查找函数 <转>
- ubuntu 关闭网卡自休眠
- Java网络编程详解
- netbeans+phpstudy
- yinyu
- R语言-发布介绍
- MYSQL数据库应用
- Windows应用程序-图形绘制
- CI 调整sql查询条件关系