建站软件 优化软件 编程软件 网页辅助 站群程序 网站程序 图像处理 资源教程 字体下载 推荐软件


您的位置:首页 > PHP学习 > 字符串中第一个不在指定字符串中出现的字符下标

字符串中第一个不在指定字符串中出现的字符下标

时间:2015-02-15 10:53:33  来源:免费模板网 作者:风雪 阅读次数 tagsstrspn

strspn(返回字符串中第一个不在指定字符串中出现的字符下标)
表头文件
1
#include <string.h>
定义函数:
1
size_t strspn (const char *s,const char * accept);
函数说明 strspn()从参数s 字符串的开头计算连续的字符,而这些字符都完全是accept 所指字符串中的字符。简单的说,若strspn()返回的数值为n,则代表字符串s 开头连续有n 个字符都是属于字符串accept内的字符。
返回值 返回字符串s开头连续包含字符串accept内的字符数目。

#include <string.h>
#include <stdio.h>
main()
{
    char *str="Linux was first developed for 386/486-based pcs.";
    printf("%d\n",strspn(str,"Linux"));
    printf("%d\n",strspn(str,"/-"));
    printf("%d\n",strspn(str,"1234567890"));
}
运行结果:
5
0
0
int strspn(const char *s,const char *accept)
{
    const char *p;
    const char *a;
    int count = 0;
    for(p = s; *p != '\0'; ++p)
    {
        for (a = accept; *a != '\0'; ++a)
        {
            if (*p == *a)
            {
                break;
            }
        }//里面的for循环到此为止
        if (*a == '\0')
        {
            return count;
        }
        ++count;
    }//外面的for循环到此为止
    return count;
}

本文地址:https://www.freemoban.com/php/2015/0215/587.html

猜你喜欢
栏目推荐
模板推荐

Copyright:www.freemoban.com 免费模板网 All Rights Reserved 网站备案:辽ICP备19014872号-2   辽公网安备 21010602000376号  辽公网安备:42900402000182号

免责声明:本站部分资源来自互联网收集,版权归原创者所有,如果侵犯了你的权益,我们会及时删除侵权内容,联系QQ:1615187561 谢谢合作!