help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to count the number of occurrences of a character in a string?


From: Eli Zaretskii
Subject: Re: How to count the number of occurrences of a character in a string?
Date: Tue, 13 Oct 2015 20:41:45 +0300

> Date: Tue, 13 Oct 2015 19:48:15 +0300
> From: Eli Zaretskii <eliz@gnu.org>
> 
> Isn't the following simpler?
> 
>   (let ((str-list (append str nil))
>         (num-matches 0))
>     (while str-list
>       (if (= (car str-list) char)
>           (setq num-matches (1+ num-matches)))
>       (setq str-list (cdr str-list)))
>       num-matches)

Which could be made even more elegant (and faster, I guess) by using
'mapc', of course.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]