直观的标题套管

时间:2016-03-04 21:01:28

标签: case autohotkey title capitalize


我正在寻找一种方法,使用Title Casing使脚本更直观。我正在寻找的是一个可以识别符号(/, - ,\等)和典型首字母缩略词(FEMA,CDC,[City] PD等)并适当应用Title Casing的脚本。我现在拥有的是:

SaveVar=%Clipboard%
Clipboard=
ClipWait, 0.5
Send ^c
ClipWait, 0.5
segment = %Clipboard%
; Replace text with text in title case
; Make words following "/" title case
StringUpper, segment, segment , T
; Process exceptions
segment := RegExReplace(segment, "\bA\b", "a")
segment := RegExReplace(segment, "\bAn\b", "an")
segment := RegExReplace(segment, "\bThe\b", "the")
segment := RegExReplace(segment, "\bTo\b", "to")
segment := RegExReplace(segment, "\bAt\b", "at")
segment := RegExReplace(segment, "\bIn\b", "in")
segment := RegExReplace(segment, "\bAs\b", "as")
segment := RegExReplace(segment, "\bAn\b", "an")
segment := RegExReplace(segment, "\bAnd\b", "and")
segment := RegExReplace(segment, "\bBut\b", "but")
segment := RegExReplace(segment, "\bOr\b", "or")
segment := RegExReplace(segment, "\bpdf\b", "PDF")
segment := RegExReplace(segment, "\bllc\b", "LLC")
segment := RegExReplace(segment, "\bdui\b", "DUI")
segment := RegExReplace(segment, "\bAmp\b", "amp")
segment := RegExReplace(segment, "\bPdf\b", "PDF")
segment := RegExReplace(segment, "\bBy\b", "by")
segment := RegExReplace(segment, "\bOf\b", "of")
segment := RegExReplace(segment, "\bFor\b", "for")
segment := RegExReplace(segment, "\b-up\b", "-Up")
; Make first letter uppercase
segment:=RegExReplace(segment, "(\w)(.+)","$U1$2")
; Replace segment text with modified contents of clipboard
Clipboard := segment
ClipWait, 0.5
Send ^v
Sleep 100
Clipboard=%SaveVar%
SaveVar=
return

这个问题是它会在符号后面小写字母,除了首字母缩略词的第一个字母之外的所有字母。有没有办法对符号后面的字母进行例外处理,或者在应用适当的情况之前在符号周围应用间距?

1 个答案:

答案 0 :(得分:0)

在线下:

segment:=RegExReplace(segment, "(\w)(.+)","$U1$2")

添加以下行:

segment:=RegExReplace(segment, "(\W)([a-z])","$1$U2")

\W是一个符号,如果后跟一个小写字母,即[a-z],则返回捕获的符号以及捕获的大写字母。