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: Emanuel Berg
Subject: Re: How to count the number of occurrences of a character in a string?
Date: Wed, 14 Oct 2015 00:00:03 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Marcin Borkowski <mbork@mbork.pl> writes:

> Should I ... use cl-count?

Why not?

(defun count-char-in-string (the-char str)
  (if (and (char-or-string-p the-char)
           (char-or-string-p str) )
      (let ((c (if (characterp the-char) the-char (string-to-char the-char))))
        (cl-count c (string-to-list str)) )
    (error "Indata verification failed.") ))

(count-char-in-string "o"  "oooiiiooo") ; 6
(count-char-in-string ?\o  "oooiiiooo") ; 6
(count-char-in-string 111  "oooiiiooo") ; 6
(count-char-in-string '(1) "oooiiiooo") ; error
(count-char-in-string "o"  '(1))        ; error

-- 
underground experts united
http://user.it.uu.se/~embe8573




reply via email to

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