计算字符串中字符的出现次数 [英] Counting occurence of character in a string

查看:62
本文介绍了计算字符串中字符的出现次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




是否有标准的库函数可以计算字符串中字符的数量?


问候,


Michael

解决方案

Michael McGarry写道:


你好,

是否有标准的库函数来计算字符串中字符的出现次数?




No.


-

pete


pete写道:

Michael McGarry写道:




是否有标准库函数计算
字符串中字符的出现?



否。




如果是,它可能会被实现沿着这条线...


size_t strccnt(const char * s,int c)

{

const unsigned cha r * us =(const unsigned char *)s;

const unsigned char uc = c;

size_t n = 0;

if( !uc)返回1;

while(* us)if(* us ++ == uc)n ++;

return n;

}


-

彼得


2005年11月21日20:30:46 -0800,Michael McGarry

< mi ************* @ gmail.com>写道:



是否有标准的库函数来计算字符串中字符的出现次数?




<<删除电子邮件的del>>


Hi,

Is there a standard library function that counts the number of
occurences of a character in a string?

Regards,

Michael

解决方案

Michael McGarry wrote:


Hi,

Is there a standard library function that counts the number of
occurences of a character in a string?



No.

--
pete


pete wrote:

Michael McGarry wrote:


Hi,

Is there a standard library function that counts the number of
occurences of a character in a string?



No.



If it were, it would probably be implemented along the lines of...

size_t strccnt(const char *s, int c)
{
const unsigned char *us = (const unsigned char *) s;
const unsigned char uc = c;
size_t n = 0;
if (!uc) return 1;
while (*us) if (*us++ == uc) n++;
return n;
}

--
Peter


On 21 Nov 2005 20:30:46 -0800, "Michael McGarry"
<mi*************@gmail.com> wrote:

Hi,

Is there a standard library function that counts the number of
occurences of a character in a string?


No
<<Remove the del for email>>


这篇关于计算字符串中字符的出现次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆