改变变量的特定字符?

时间:2015-06-04 18:08:50

标签: autohotkey

是否可以在AutoHotkey中定位变量中的特定字符?在这种情况下,我希望变量中的第一个字符大写/小写。

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.Center
paragraphStyle.lineHeightMultiple = 0.75

var attrString = NSMutableAttributedString(string: value)
attrString.addAttribute(NSParagraphStyleAttributeName, value:paragraphStyle, range:NSMakeRange(0, attrString.length))

// showLabel.clipsToBounds = false // has no effect
showLabel.attributedText = attrString
// showLabel.sizeToFit() // also appears to have no effect

2 个答案:

答案 0 :(得分:2)

在您的情况下,StringUpper会执行:

stringUpper, foo, foo, T

T代表:

  

该字符串将转换为标题大小写。例如,“GONE with the WIND”将成为“Gone With the Wind”。 “

除此之外,您始终可以使用StringTrimRight/LeftSubStr()确定子字符串,更改它们并在之后附加它们:

firstLetter     := subStr(foo, 1, 1)
stringUpper, firstLetter, firstLetter
remainingLetters := subStr(foo, 2, strLen(foo))
foo := firstLetter . remainingLetters
; or, equally:
; foo = %firstLetter%%remainingLetters%

答案 1 :(得分:2)

@ Blauhirn解决方案的替代方案:

MsgBox % foo := Format("{:U}",  SubStr(foo, 1,1)) . subStr(foo, 2, strLen(foo))

这也可以在RegEx中完成。

::::::被修改::::::::::

这是一个完整的示例,它使用连接已删除......

fu := "fu"
bar := "beyond all recognition!"
MsgBox % capitalize(fu) A_space capitalize(bar)
Return 

capitalize(x) {
return Format("{:U}",  SubStr(x, 1,1)) subStr(x, 2, strLen(x))
}

正则表达式:

;This is the only example that accounts for Whitespace
var := "   regex is cool!"             
MsgBox % RegExReplace(var, "^(\s*)(.)", "$1$u2")

NumPut / DllCall:

var := "autohotkey is awesome!"
NumPut(Asc(DllCall("CharUpperA", Str,Chr(NumGet( var,0,"UChar")),Str)), var,0,"UChar")
MsgBox % var