Emacs Lisp中的replace-char?

bor*_*yer 5 emacs elisp

Emacs Lisp replace-string已经没有了replace-char.我想用常规ASCII引号替换"印刷"卷曲引号(此字符的Emacs代码是十六进制53979),我可以这样做:

(replace-string (make-string 1 ?\x53979) "'")
Run Code Online (Sandbox Code Playgroud)

我认为这会更好replace-char.

做这个的最好方式是什么?

cjm*_*cjm 7

为什么不用

(replace-string "\x53979" "'")
Run Code Online (Sandbox Code Playgroud)

要么

(while (search-forward "\x53979" nil t)
    (replace-match "'" nil t))
Run Code Online (Sandbox Code Playgroud)

正如replace-string文档中的建议?


小智 6

这是我替换elisp中的字符的方式:

(subst-char-in-string ?' ?’ "John's")
Run Code Online (Sandbox Code Playgroud)

得到:

"John’s"
Run Code Online (Sandbox Code Playgroud)

请注意,此函数不接受字符作为字符串.第一个和第二个参数必须是文字字符(使用?符号或string-to-char).

另请注意,如果可选inplace参数为非零,则此函数可能具有破坏性.