From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: count char in string [The Emacs Challenge Competition - round 2, with fallout] Date: Thu, 29 Oct 2020 11:38:09 +0100 Message-ID: <87k0v9fhbi.fsf@rub.de> References: <87r1pj41wa.fsf@zoho.eu> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18143"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 29 11:38:46 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kY5KQ-0004dz-5d for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 29 Oct 2020 11:38:46 +0100 Original-Received: from localhost ([::1]:36420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kY5KP-0006lb-7j for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 29 Oct 2020 06:38:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47252) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kY5Jy-0006lS-NM for help-gnu-emacs@gnu.org; Thu, 29 Oct 2020 06:38:18 -0400 Original-Received: from mout.gmx.net ([212.227.17.20]:42657) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kY5Jw-0004UI-RW for help-gnu-emacs@gnu.org; Thu, 29 Oct 2020 06:38:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1603967893; bh=tRGCNWZD6htcQN5Y03XXlKtidcjdLgHT83NzTKIaR2Y=; h=X-UI-Sender-Class:From:To:Subject:References:Date:In-Reply-To; b=lDUIhPy+rq7zYsFAFykk9Id+a07+jUZqc4sOaL4xxfvucq6xWDgt0MBvfz6vFEWFm OKWfq+nLc6k4W1EjjDJi2JxNAdWOtRgUUyiG6a4ajaJV62Iv50XNos/LntbF8B5rrN D1WYtkIQwvZzZkjaanMu5vGc1txJhYr/MRNBKihg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from strobe-jhalfs ([178.6.218.181]) by mail.gmx.com (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MSt8Q-1kwvk300h4-00UGWT for ; Thu, 29 Oct 2020 11:38:13 +0100 In-Reply-To: <87r1pj41wa.fsf@zoho.eu> (Emanuel Berg via Users list for the's message of "Wed, 28 Oct 2020 01:42:13 +0100") X-Provags-ID: V03:K1:umxdSeTqkHeGMQwtIgTPxIUoyUZvVUcL4LfN/sC3k9l5SnE+7V9 rXgpoVRuwHN6MVxidNPon3QL4jeXTGc1MUYKbxaa8IFlTdojAJ7T+EdGLHjIramnqTZJJY5 bLSglPOZJLMgOwNwwqZ72J0lPbyUSTZxisr3LOF2jQ+eZfE7g7kTinSB1xWODggmQ/zZG/y U05SJ01oEymYrlDGE1PfA== X-UI-Out-Filterresults: notjunk:1;V03:K0:h7vR9xlBcAI=:r2LJSx7iqz+5dOy9b7gUpW nK77flPyMZRxb9TyIt76irZOT9KbObiPd1t8+JYW6DF4+PhnOqUMzq62pv9JDmq/Wjm6gyqdI 8wNr8u5zs6GRUoDayOz/r1rmMaV4tvbPRlJA/6ayY7MGPDH11VRdrU+K/VgyGF3ceEiZhVzzl IIeDP+1yQkKNZTgXWpkbZ+RBkcKnxkC6+ads0IxI0BT7CI5cOrGdf6ITX+H1TV+OjfIcwEvV1 /s5pLVL7SCbUxDedXFwzHWlb2vRPavVi1ERnpLZRvn4Kl4mzUXwa3omV07BMBcq1aP5HBCnnC 0WUeiXKoim1nUg0SXb5vw6NB0PsmVriaGDC314WheOwy4fmjcXK+rDBx6WXJhoXg45cX/GfXZ osFaRfu8pnPTjkRKDazN5u7RiPQrZaziRqkFRD1AE68WBuFlJKR1Yh9C7BIv+js9uN3lEqOgh INNCt9JImk9XlJUu0IHeMlNK4JaPYLeiAD1my91Rg5636htEhgLlIuWTnHIUyxoNAW/1ZGhi3 OvBp/aL7cd0+F3xx38Nc4EeZNU+dgDijjIGCdvG4cR/u6gTPiXWlC4cemGtqdEBCoWuLvIKog gfi9/r+F9K+6roJbuOAI/iL2lHBL+Vv7ff34y+4ty9JHa7I0OGGX/0W1+TmdR2s39LiwN/IaT OMWOeg+gGLMNaeUFWBs86odvDn1rShC02CKkF8gxL/hOIFGGkh85SJ787Z23BMDIRh2yEnXuc C82zfhSFTLBM3POTyf2y6ShNpYnv6rK6ls58pMrkNpwlc1YeqlrSpDfHUj5BJX6TEqeyVhNb Received-SPF: pass client-ip=212.227.17.20; envelope-from=stephen.berman@gmx.net; helo=mout.gmx.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/29 06:38:13 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:124794 Archived-At: On Wed, 28 Oct 2020 01:42:13 +0100 Emanuel Berg via Users list for the GNU Emacs text editor wrote: > round 2: > > Very simple: we are looking for a function that returns the number of > occurrences of a char in a string. cl-count? seq-count? seq-reduce? KISS! (defun count-char-in-string (char str) "Return number of occurrences of character CHAR in string STR." (let ((count 0)) (dotimes (i (length str) count) (when (eq char (aref str i)) (setq count (1+ count)))))) Steve Berman