2

I was very surprised not to be able to find this in the elisp manual or SO. I just want the equivalent of many languages' chr() and ord() or similar: convert between actual characters and their (unicode) code point values.

Emacs Lisp: getting ascii value of character explains that to elisp, a char just is its code-point. But what if I need the representation of that char~int as a series of ASCII decimal digits?

For example, if I wanted to generate in a buffer, a readable table showing the equivalences?

Thanks!

Community
  • 1
  • 1
TextGeek
  • 1,196
  • 11
  • 23
  • Possible duplicate of [Emacs Lisp: getting ascii value of character](http://stackoverflow.com/questions/19862517/emacs-lisp-getting-ascii-value-of-character) – Steve Vinoski Oct 07 '16 at 12:27

1 Answers1

4

As you've already noted, characters are integers.

(eq ?A 65)

For example, if I wanted to generate in a buffer

Either of the following inserts the character A into the buffer:

(insert ?A)
(insert 65)

If you need to deal with strings, characters can be converted to strings:

(char-to-string ?A)
(char-to-string 65)
(format "%c" 65)
"A"

vs

(number-to-string 65)
(format "%d" 65)
"65"
phils
  • 71,335
  • 11
  • 153
  • 198