Chinaunix首页 | 论坛 | 博客
  • 博客访问: 49338
  • 博文数量: 33
  • 博客积分: 223
  • 博客等级: 入伍新兵
  • 技术积分: 220
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-03 21:08
文章分类

全部博文(33)

文章存档

2015年(1)

2013年(1)

2012年(31)

分类:

2012-05-01 22:41:30

原文地址:strspn() ,strspn函数 作者:gofiend



strspn(返回字符串中连续不含指定字符串内容的字符数)


表头文件
#include
定义函数
size_t strspn (const char *s,const char * accept);
函数说明
strspn()从参数s 字符串的开头计算连续的字符,而这些字符都完全是accept 所指字符串中的字符。简单的说,若strspn()返回的数值为n,则代表字符串s 开头连续有n 个字符都是属于字符串accept内的字符。
返回值
返回字符串s开头连续包含字符串accept内的字符数目。
范例
#include
范例
#include
#include
main()
{
char *str="Linux was first developed for 386/486-based pcs.";
printf("%d\n",strcspn(str," "));
printf("%d\n",strcspn(str,"/-"));
printf("%d\n",strcspn(str,"1234567890"));
}


执行
5 /*计算大小写字母。不包含“ ”,所以返回Linux的长度。*/




size_t strspn ( const char * str1, const char * str2 );

Get span of character set in string

Returns the length of the initial portion of str1 which consists only of characters that are part of str2.

Parameters

str1
C string to be scanned.
str2
C string containing the characters to match.

Return value

The length of the initial portion of str1 containing only characters that appear in str2.
Therefore, if all of the characters in str1 are in str2, the function returns the length of the entire str1 string, and if the first character in str1 is not in str2, the function returns zero.


==========================================================



strcspn(返回字符串中连续不含指定字符串内容的字符数)
相关函数
strspn
表头文件
#inclued
定义函数
size_t strcspn ( const char *s,const char * reject);
函数说明
strcspn()从参数s字符串的开头计算连续的字符,而这些字符都完全不在参数reject 所指的字符串中。简单地说,若strcspn()返回的数值为n,则代表字符串s开头连续有n个字符都不含字符串reject内的字符。
返回值
返回字符串s开头连续不含字符串reject内的字符数目。
范例
#include
#include
main()
{
char *str="Linux was first developed for 386/486-based pcs.";
printf("%d\n",strcspn(str," "));
printf("%d\n",strcspn(str,"/-"));
printf("%d\n",strcspn(str,"1234567890"));
}
执行
5 /*只计算到“ ”的出现,所以返回“Linux”的长度*/
33 /*计算到出现“/”或“-”,所以返回到“6”的长度*/
30 /* 计算到出现数字字符为止,所以返回“3”出现前的长度*/
 

阅读(2493) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~