(standard c libraries translation )index
来源:互联网 发布:淘宝手机端模板编辑 编辑:程序博客网 时间:2024/04/29 08:05
index, rindex - locate character in string
index,rindex-在字符串中定位字符
所需头文件
#include <strings.h>
char *index(const char *s, int c);
char *rindex(const char *s, int c);
The index() function returns a pointer to the first occurrence of the character c in the string s.
The rindex() function returns a pointer to the last occurrence of the character c in the string s.
The terminating null byte ('\0') is considered to be a part of the strings.
index函数返回一个指向字符串s中字符c第一次出现的位置
rindex函数返回一个指向字符串s中字符c最后一次出现的位置
字符串必须包含结束字符\0
返回值
The index() and rindex() functions return a pointer to the matched character or NULL if the character is not found.
index()和rindex()函数返回一个指向匹配字符的指针,如果没有找到则返回NULL
marked as LEGACY in POSIX.1-2001. POSIX.1-2008 removes the specifications of index() and rindex(), recommending strchr(3) and strrchr(3) instead.
在POSIX.1-2001中被标记,在POSIX.1-2008中删掉了index()和rindex的定义,推荐使用strchr和strrchr作为替代
运行结果如下:
index,rindex-在字符串中定位字符
所需头文件
#include <strings.h>
char *index(const char *s, int c);
char *rindex(const char *s, int c);
The index() function returns a pointer to the first occurrence of the character c in the string s.
The rindex() function returns a pointer to the last occurrence of the character c in the string s.
The terminating null byte ('\0') is considered to be a part of the strings.
index函数返回一个指向字符串s中字符c第一次出现的位置
rindex函数返回一个指向字符串s中字符c最后一次出现的位置
字符串必须包含结束字符\0
返回值
The index() and rindex() functions return a pointer to the matched character or NULL if the character is not found.
index()和rindex()函数返回一个指向匹配字符的指针,如果没有找到则返回NULL
marked as LEGACY in POSIX.1-2001. POSIX.1-2008 removes the specifications of index() and rindex(), recommending strchr(3) and strrchr(3) instead.
在POSIX.1-2001中被标记,在POSIX.1-2008中删掉了index()和rindex的定义,推荐使用strchr和strrchr作为替代
testcase如下:
#include <stdio.h>#include <string.h>int main(void){char *s = "abcddcba";char *tmp = index(s, 'b');printf("tmp = %s\n", tmp);tmp = rindex(s, 'b');printf("tmp = %s\n", tmp);return 0;}
运行结果如下:
cheny.le@cheny-ThinkPad-T420:~/cheny/testCode$ ./a.out
tmp = bcddcba
tmp = ba
0 0
- (standard c libraries translation )index
- (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 )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
- (standard c libraries translation )strpbrk
- makefile -objs的用法及作用
- Java序列化的机制和原理
- android中图片的三级cache策略(内存、文件、网络)之二:内存缓存策略
- linux自动挂载文件系统详解
- 发散式button按钮动画效果
- (standard c libraries translation )index
- 【Redis笔记】 第2篇: redis.conf基本配置项说明
- 获取myeclipse下的项目路径
- c语言经典面试题
- UVa401_Palindromes(小白书字符串专题)
- 模式匹配,KMP 算法精华部分
- 简单的TextView自定义控件,实现左右加减按钮
- 编写一个垃圾回收器
- C#中通过DataGrid显示隶属关系