【问题标题】:How can I convert a series of words into camel case in AppleScript?如何在 AppleScript 中将一系列单词转换为驼峰式大小写?
【发布时间】:2015-06-29 08:11:39
【问题描述】:

我正在尝试修改 Dragon Dictate,它可以使用一系列已说出的单词来执行 AppleScript。我需要找出如何获取包含这些单词的字符串并将其转换为驼峰式大小写。

on srhandler(vars)
    set dictatedText to varDiddly of vars
    say dictatedText
end srhandler

所以如果我设置一个宏来执行上面的脚本,称为camel,我说“camel string with string”,dictedText 将被设置为“string with string”。这是DD的一个很酷的功能。但是我不知道 AppleScript,所以我不知道如何将“带字符串的字符串”转换为驼峰式,即 stringWithString。

如果我能学会这个基本的东西,我也许可以最终开始通过语音编程,这比处理流行的小键盘和游戏键盘更好,但我觉得它们很糟糕。

【问题讨论】:

标签: macos applescript voice-recognition camelcasing dictation


【解决方案1】:

如果您只需要将短语转换为驼色文本,我会这样做:

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" 为真,您只需将任何所需字母与其大写字母进行比较,然后替换它。

我希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2017-07-28
    • 2018-12-18
    • 2011-08-14
    • 2011-02-27
    • 1970-01-01
    • 2017-08-18
    • 2021-04-27
    • 1970-01-01
    相关资源
    最近更新 更多