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

[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: Sat, 28 Nov 2020 02:26:38 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Corwin Brust wrote:

> (defun count-char-in-string (string char)
>      "Return the number of occurances of CHAR in STRING."
>      (seq-count (apply-partially 'eq char)
>             (seq-into string 'list)))

OK, that looks better than mine so I take it. But you have to
require seq or the byte compiler will complain.

(require 'seq)

(defun count-char-in-string (string char)
  (seq-count (apply-partially 'eq char) (seq-into string 'list)) )

;; (count-char-in-string "Emacs skills kills" ?a) ; 1

> (count-char-in-string "hii" ?I) ;; ⇒ 2

That's 0 :) because it is case sensitive (as it should)

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




reply via email to

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