Autohotkey - Replace different words or sentences

半腔热情 提交于 2020-01-06 08:17:34

问题


in this script that I use i can replace only one word teams--> milan, juventus, inter.. But i want replace many words (not only one word) for example:

[simply word replacement jack-->beta]

alfa-->beta

[sentence replacement jack-->jack,john,alfa]

jack

jack
john
alfa

This is actually code that i use

loop {
    While !RegexMatch(strCapture, "teams$") {
        Input, strUserInput, V L1, {BackSpace}  ; V: visible, L1: Character length 1
        If ErrorLevel = Endkey:BackSpace
            strCapture := SubStr(strCapture, 1, StrLen(strUserInput) - 1) 
        else
            strCapture .= strUserInput
        ; tooltip % ErrorLevel "`n" strUserInput "`n" strCapture "`n" ; enable this to see what actually happens
    }
    SendInput,
    (Ltrim
        {Backspace 5}
        milan
        juventus
        inter
        roma
        lazio
        napoli
        mantova
    )
    strCapture := ""
}

How can I modify the code?
It is also possible to run the script integrating copy-paste?


回答1:


You could use a For loop to replace the contents, but this would become increasingly tedious to maintain at scale, so YMMV.

The following will use the clipboard contents as the to/from variables, but you can swap it out with a variable as desired (replace "clipboard" with your string variable).

F3::
{
    replace := {"alfa":"beta", "gamma":"delta"}
    For start, end in replace {
    StringReplace, clipboard, clipboard, %start%, %end%, All
}}
Return


来源:https://stackoverflow.com/questions/13660847/autohotkey-replace-different-words-or-sentences

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!