[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: count matches in string, not region?
From: |
Tassilo Horn |
Subject: |
Re: count matches in string, not region? |
Date: |
Wed, 26 Feb 2020 20:49:51 +0100 |
User-agent: |
Cyrus-JMAP/3.1.7-947-gbed3ff6-fmstable-20200220v2 |
Another way would be
(string-match-p "^[[:digit:]]\\{13\\}$" isbn)
which returns non-nil iff isbn is a string of exactly thirteen digits.
Bye,
Tassilo
Am Mi, 26. Feb 2020, um 07:24, schrieb Emanuel Berg via Users list for the GNU
Emacs text editor:
> > Anyway as you see the 4th line doesn't look
> > good, instead of moving the point one would
> > like to invoke the/a count function with the
> > already-fetched isbn-as argument.
> >
> > So is there a count-matches-in-string or
> > something to that extent anywhere, that you
> > are aware of?
>
> Problem solved with `replace-regexp-in-string'.
>
> Can still be useful to count matches in
> a string, I guess...
>
> Yank it in a temporary buffer and then use
> region there is perhaps a poor man's solution...
>
> (defun check-isbn-at-point ()
> "Compute and echo the check digit from the ISBN at point."
> (interactive)
> (let*((isbn-string (thing-at-point 'symbol t))
> (digits-only (replace-regexp-in-string "[^0-9]" "" isbn-string))
> (num-digits (length digits-only))
> (check-digit (if (> num-digits 10)
> (checksum-isbn-13 digits-only)
> (checksum-isbn-10 digits-only) )))
> (message "check digit: %s" check-digit)
> ))
> (defalias 'ciap #'check-isbn-at-point)
>
> --
> underground experts united
> http://user.it.uu.se/~embe8573
> https://dataswamp.org/~incal
>
>
>
>