简体   繁体   English

如何在自动热键中连接字符串数组

[英]How to concatenate a string array in auto hotkey

Those who use, know, how useful automation tool AHK is..那些使用过的人都知道,自动化工具 AHK 是多么有用。

The AHK has function StringSplit or StrSplit() which does very fast split string into array elements. AHK 有 function StringSplit 或StrSplit()可以非常快速地将字符串拆分为数组元素。

This is very useful if you want to manipulate some parts of well formed string, but unfortunately it appears there is no way around!如果您想操纵格式良好的字符串的某些部分,这非常有用,但不幸的是,似乎没有办法!

I spend time searching and there was a mess of samples with old syntax which just does not work.我花时间搜索,有一堆旧语法的样本,这些样本不起作用。 All I wanted is Final_Concatenated_String:= StrConcat(My_Array_Of_Strings, "\") which obviously does not work!我想要的只是Final_Concatenated_String:= StrConcat(My_Array_Of_Strings, "\")这显然不起作用!

So, simple question: how to concatenate simple array of strings?所以,一个简单的问题:如何连接简单的字符串数组?

Spending lot of time, and finding old syntax examples which does not work made my do hard way, to make it simple.花费大量时间并找到不起作用的旧语法示例使我很难做到,以使其变得简单。

Simple and fast solution for concatenating directory spliced into strings array:将目录拼接成字符串数组的简单快速的解决方案:

Loop, % folder_path_array.MaxIndex()   ; concat string array
    {
        folder_path .= folder_path_array[A_Index]"\"
    }

More advanced version, in case you have ending backslash in path field:更高级的版本,如果您在路径字段中有结束反斜杠:

Loop, % folder_path_array.MaxIndex()   ; concat array
    { if folder_path_array[A_Index]    ; if [last] element of array is empty, skip it 
        folder_path .= folder_path_array[A_Index]"\"
    }

In more deep details.在更深入的细节。 I needed to copy directory path from input field, change the root directory, paste it back to input field and save it.我需要从输入字段复制目录路径,更改根目录,将其粘贴回输入字段并保存。

So I ended up with this script:所以我最终得到了这个脚本:

SendInput, ^a                ; select all input field text
SendInput, ^c                ; copy current selection to clipboard
ClipWait, 30

folder_path_array := StrSplit(Clipboard, "\")   ; split folder path into strings of array
folder_path_array[2] .= "_backup"           ; prepend string to root folder, first element is "C:"

    Loop, % folder_path_array.MaxIndex()   ; concat string array
        { if folder_path_array[A_Index]    ; if [last] element of array is empty, skip it 
            folder_path .= folder_path_array[A_Index]"\"
        }


Clipboard := folder_path        ; load the new string to clipboard
SendInput, ^v                   ; paste the new string into input field

Hope it will help somebody also.希望它也会对某人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM