Linux中 strsep 函数 详解
来源:互联网 发布:阿里云cdn流量包怎么用 编辑:程序博客网 时间:2024/06/05 15:01
现出原型:
char *strsep(char **stringp, const char *delim)
参数1:指向字符串的指针的指针,
参数2:指向字符的指针
功能:以参数2所指的字符作为分界符,将参数1的值所指的字符串分割开,返回值为被参数2分开的左边的那个字符串,同时会导致参数1的值(指向位置)发生改变,即,参数1的值会指向分隔符号右边的字符串的起始位置(这一点会比较有用,比如:“1999-12-14”,可以用这个方法很容易的被提取出各个项)!
以下是一个例子,看看运行结果你就很明白了!
#include <string.h>
#include <stdlib.h>
int main()
{
char ptr[]={ "abcdefghijklmnopqrstuvwxyz "};
char *p,*str= "m ";
p=ptr;
printf( "%s\n ",strsep(&p,str));
printf( "%s\n ",p);
str= "s ";
printf( "%s\n ",strsep(&p,str));
printf( "%s\n ",p);
}
//*****结果**************结果**************结果***************************
[root@shwhg test]# gcc test131.c
[root@shwhg test]# ./a.out
abcdefghijkl
nopqrstuvwxyz
nopqr
tuvwxyz
//***************************************************************************
char *strsep(char **stringp, const char *delim)
参数1:指向字符串的指针的指针,
参数2:指向字符的指针
功能:以参数2所指的字符作为分界符,将参数1的值所指的字符串分割开,返回值为被参数2分开的左边的那个字符串,同时会导致参数1的值(指向位置)发生改变,即,参数1的值会指向分隔符号右边的字符串的起始位置(这一点会比较有用,比如:“1999-12-14”,可以用这个方法很容易的被提取出各个项)!
以下是一个例子,看看运行结果你就很明白了!
#include <string.h>
#include <stdlib.h>
int main()
{
char ptr[]={ "abcdefghijklmnopqrstuvwxyz "};
char *p,*str= "m ";
p=ptr;
printf( "%s\n ",strsep(&p,str));
printf( "%s\n ",p);
str= "s ";
printf( "%s\n ",strsep(&p,str));
printf( "%s\n ",p);
}
//*****结果**************结果**************结果***************************
[root@shwhg test]# gcc test131.c
[root@shwhg test]# ./a.out
abcdefghijkl
nopqrstuvwxyz
nopqr
tuvwxyz
//***************************************************************************
0 0
- Linux中 strsep 函数 详解
- Linux中 strsep 函数 详解
- strtok和strsep函数详解
- strtok和strsep函数详解
- strtok和strsep函数详解
- strtok和strsep函数详解
- strtok和strsep函数详解
- strtok和strsep函数详解
- strtok和strsep函数详解
- strsep 函数
- strsep 函数
- strsep函数
- strsep() 函数
- Linux 内核可用的字符串分割函数 strsep (String Split Function strsep in Linux Kernel)
- strsep字符串分割详解
- strsep函数用法
- strsep函数用法
- 字符串分割函数strsep
- iOS tableview cell的展开收缩
- Problem B: 使用指针访问数组元素--程序填空
- 给分类(Category)添加属性
- leetcode 168 Excel Sheet Column Title
- 自定义EditText样式及光标
- Linux中 strsep 函数 详解
- 观察者模式(Observer) Java
- canvas的save,restore方法的使用理解
- scp或ssh登录时遇到Host key verification failed问题的解决方法
- Redis 相关学习
- Python Collections Counter
- VS2005 添加lib 的方法
- PHP class
- Problem C: C语言习题 整数排序