繁体   English   中英

如何在Emacs中大写英文字符串

[英]How to capitalize english string in Emacs

我想知道人们使用什么来正确地大写英文字符串,因为“ capitalize”将无法完成工作:

(capitalize "can't")
=> "Can'T"

尽管编写此函数很简单,但我想知道是否存在一种首选的内置方法来实现。

也许如果您暂时将'添加到当前单词构成语法表中:

(modify-syntax-entry ?' "w")

(capitalize "can't")
=> "Can't"

我有Mc一定要大写单词,并且它can't正确地大写。

当前的答案很好,但是如果您在代码中使用字符串,则可以使用s字符串操作库。 s-capitalize将句子中的第一个单词大写。

ELISP> (s-capitalize "can't win the war on drugs in a prison, where the hell you gonna win it?")
"Can't win the war on drugs in a prison, where the hell you gonna win it?"
ELISP> (s-join " " (-map 's-capitalize (s-split " " "can't win the war on drugs in a prison, where the hell you gonna win it?")))
"Can't Win The War On Drugs In A Prison, Where The Hell You Gonna Win It?"

s-titleize将字符串中的每个单词s-titleize大写,但这是对内置capitalize的简单包装,因此适用了Karl Voigtland的变通方法

ELISP> (s-titleize "Girl, you can't even think of calling this shit a war.")
"Girl, You Can'T Even Think Of Calling This Shit A War."
ELISP> (progn (modify-syntax-entry ?' "w") (s-titleize "Girl, you can't even think of calling this shit a war."))
"Girl, You Can't Even Think Of Calling This Shit A War."

该行为当然取决于所使用的语法表,即取决于主模式。 如果'字符具有"wp"语法,则它应该可以正常工作。 在文本模式下就是这种情况,但在大多数编程模式下并非如此。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM