(standard c libraries translation )strstr
来源:互联网 发布:程序员soho 编辑:程序博客网 时间:2024/06/14 04:30
strstr, strcasestr - locate a substring
定位子串
所需头文件
#include <string.h>
char *strstr(const char *haystack, const char *needle);
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <string.h>
char *strcasestr(const char *haystack, const char *needle);
The strstr() function finds the first occurrence of the substring needle in the string haystack. The terminating null bytes ('\0') are not compared.
The strcasestr() function is like strstr(), but ignores the case of both arguments.
strstr函数在haystack字符串里面查找跟needle字符串相等的子串,字符串结束符\0不参与比较
strcasestr函数跟strstr类似,但是忽略大小写
These functions return a pointer to the beginning of the substring, or NULL if the substring is not found.
这些函数返回匹配字串的开始处,如果没有找到匹配的子串则返回NULL
The strstr() function conforms to C89 and C99. The strcasestr() function is a nonstandard extension.
strstr函数遵从C89和C99标准,strcasestr函数不是一个标准的实现
Early versions of Linux libc (like 4.5.26) would not allow an empty needle argument for strstr(). Later versions (like 4.6.27) work correctly, and return haystack when needle is empty.
运行结果如下:
定位子串
所需头文件
#include <string.h>
char *strstr(const char *haystack, const char *needle);
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <string.h>
char *strcasestr(const char *haystack, const char *needle);
The strstr() function finds the first occurrence of the substring needle in the string haystack. The terminating null bytes ('\0') are not compared.
The strcasestr() function is like strstr(), but ignores the case of both arguments.
strstr函数在haystack字符串里面查找跟needle字符串相等的子串,字符串结束符\0不参与比较
strcasestr函数跟strstr类似,但是忽略大小写
These functions return a pointer to the beginning of the substring, or NULL if the substring is not found.
这些函数返回匹配字串的开始处,如果没有找到匹配的子串则返回NULL
The strstr() function conforms to C89 and C99. The strcasestr() function is a nonstandard extension.
strstr函数遵从C89和C99标准,strcasestr函数不是一个标准的实现
Early versions of Linux libc (like 4.5.26) would not allow an empty needle argument for strstr(). Later versions (like 4.6.27) work correctly, and return haystack when needle is empty.
早期linux libc(例如4.5.26)不允许needle参数是NULL,后续的版本(例如4.6.27)已经ok,当needle是NULL的时候返回haystack
testcase如下:
#define _GNU_SOURCE#include <stdio.h>#include <string.h>int main(void){const char *src = "abcdefg";const char *needle1 = "cd";const char *needle2 = "dE";char *tmp = NULL;tmp = strstr(src, needle1);printf("tmp = %s\n", tmp);tmp = strcasestr(src ,needle2);printf("tmp = %s\n", tmp);return 0;}
运行结果如下:
cheny.le@cheny-ThinkPad-T420:~/cheny/testCode$ ./a.out
tmp = cdefg
tmp = defg
0 0
- (standard c libraries translation )strstr
- (standard c libraries translation)isalpha家族
- (standard c libraries translation )atoi家族
- (standard c libraries translation)alloca
- (standard c libraries translation )sbrk家族
- (standard c libraries translation )malloc家族
- (standard c libraries translation )getpagesize
- ( standard c libraries translation )time家族
- (standard c libraries translation )bcmp家族
- (standard c libraries translation )index
- ( standard c libraries translation )memcpy家族
- (standard c libraries translation )strcmp家族
- (standard c libraries translation )strcat
- (standard c libraries translation )strchr
- (standard c libraries translation )strspn
- (standard c libraries translation )strcpy
- (standard c libraries translation )strdup
- (standard c libraries translation )strlen
- CPU正弦曲线
- 网站备案需要准备的资料列表信息
- [Effective WX] wxGTK上popup wxMenu的一个crash问题分析及解决方案
- 看unix高级编程时遇到apue.h找不到的问题
- Linux 下 Tomcat 自启动配置
- (standard c libraries translation )strstr
- Java SE7新特性之二进制字面量
- Underscore.js 1.3.3 中文解释
- [转载]pl/sql动态调用带参数的存储过程
- UML之交互图
- 网络工程师三级进阶(转)
- Java SE7新特性之switch语句中使用字符串
- Network-attached storage (NAS)
- Visual Studio 11可视化多核多线程编程的行为