更新时间:2022-01-07 05:15:10
如果您只需要将短语转换为驼峰文本,我会这样做:
If you only need to convert a phrase to camel text, here is how I would do it:
set targetString to "string with string"
set allCaps to every character of "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
global allCaps
set camel to my MakeTheCamel(targetString)
to MakeTheCamel(txt)
set allWords to every word of txt
set camelString to ""
repeat with eachWord in allWords
set char01 to character 1 of (eachWord as text)
set remainder to characters 2 thru -1 of (eachWord as text)
repeat with eachChar in allCaps
if char01 = (eachChar as text) then
set camelString to camelString & (eachChar as text) & (remainder as text)
exit repeat
end if
end repeat
end repeat
return camelString
end MakeTheCamel
由于 AppleScript 认为 "a" = "A"
为真,您只需将任何所需的字母与其大写字母进行比较,然后替换它.
Since AppleScript considers "a" = "A"
to be true, you need only compare any desired letter to its capitalized equivalent, and replace it.
我希望这会有所帮助.