簡體   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