本文介绍了如何从流程输出中删除换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我称git获取顶级目录(根据
)。
I call git get the toplevel dir (according toIs there a way to get the git root directory in one command?).
(let ((tmpbuffer (get-buffer-create (make-temp-name "git"))))
(call-process "git" nil tmpbuffer nil "rev-parse" "--show-toplevel")
(with-current-buffer tmpbuffer
(with-output-to-string
(princ (buffer-string))
(kill-buffer))))
但是返回的字符串中有尾随换行符。我不确定如何摆脱它。
But there's a trailing newline in the string returned. I'm not sure how to get rid of it.
推荐答案
我想你可以
I think you can do
(replace-regexp-in-string "\n$" ""
(shell-command-to-string "git rev-parse --show-toplevel"))
这篇关于如何从流程输出中删除换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!