[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: count char in string [The Emacs Challenge Competition - round 2, wit
From: |
Emanuel Berg |
Subject: |
Re: count char in string [The Emacs Challenge Competition - round 2, with fallout] |
Date: |
Sun, 29 Nov 2020 04:44:13 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Corwin Brust wrote:
>> You don't need the seq-into, just pass string directly to
>> seq-count.
>
> Oh -- nice, thanks Noam!
So this is the best solution, right?
(require 'seq)
(defun count-char-in-string (str char)
(seq-count (lambda (c) (= c char)) str) )
;; (count-char-in-string "Emacs skills kills" ?a) ; 1
;; (count-char-in-string "Emacs skills kills" ?A) ; 0
;; (count-char-in-string "Emacs skills kills" ?l) ; 4
https://dataswamp.org/~incal/emacs-init/count.el
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal