[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: |
Wed, 14 Oct 2015 20:06:41 +0300 |
> From: Oleh Krehel <ohwoeowho@gmail.com>
> Date: Wed, 14 Oct 2015 12:04:52 +0200
>
> (defun my-count (char str)
> (let ((count 0)
> (end (length str))
> (i 0)
> x)
> (while (< i end)
> (setq x (aref str i))
> (if (eq char x)
> (setq count (1+ count)))
> (setq i (1+ i)))
> count))
>
> While `my-count' is twice as fast, I'd still recommend to use
> `cl-count', unless the code is very performance-critical.
Why? There's nothing wrong with aref.
- Re: How to count the number of occurrences of a character in a string?, (continued)
- Re: How to count the number of occurrences of a character in a string?, Eli Zaretskii, 2015/10/13
- Re: How to count the number of occurrences of a character in a string?, Kaushal Modi, 2015/10/15
- Re: How to count the number of occurrences of a character in a string?, Eli Zaretskii, 2015/10/13
- Re: How to count the number of occurrences of a character in a string?, Kaushal Modi, 2015/10/13
- Re: How to count the number of occurrences of a character in a string?, Eli Zaretskii, 2015/10/13
- Re: How to count the number of occurrences of a character in a string?, Kaushal Modi, 2015/10/13
- Message not available
- Re: How to count the number of occurrences of a character in a string?, Brendan Halpin, 2015/10/13
- Re: How to count the number of occurrences of a character in a string?, Kaushal Modi, 2015/10/13
- Message not available
- Re: How to count the number of occurrences of a character in a string?, Joost Kremers, 2015/10/13
- Re: How to count the number of occurrences of a character in a string?, Oleh Krehel, 2015/10/14
- Re: How to count the number of occurrences of a character in a string?,
Eli Zaretskii <=
- Re: How to count the number of occurrences of a character in a string?, Michael Heerdegen, 2015/10/13
- Re: How to count the number of occurrences of a character in a string?, Charles Curley, 2015/10/15
- Re: How to count the number of occurrences of a character in a string?, Noam Postavsky, 2015/10/15
- Re: How to count the number of occurrences of a character in a string?, Kaushal Modi, 2015/10/14
Re: How to count the number of occurrences of a character in a string?, Emanuel Berg, 2015/10/13
Re: How to count the number of occurrences of a character in a string?, Joost Kremers, 2015/10/12