如何在自动热键中连接字符串数组 [英] How to concatenate a string array in auto hotkey

查看:56
本文介绍了如何在自动热键中连接字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那些使用,知道AHK自动化工具多么有用的人.

Those who use, know, how useful automation tool AHK is..

AHK具有函数StringSplit或 StrSplit()非常快地将字符串拆分为数组元素.

The AHK has function StringSplit or StrSplit() which does very fast split string into array elements.

如果您要操纵格式良好的字符串的某些部分,这将非常有用,但不幸的是,似乎无法解决!

This is very useful if you want to manipulate some parts of well formed string, but unfortunately it appears there is no way around!

我花了很多时间搜索,发现一堆带有旧语法的示例不起作用. 我想要的就是 Final_Concatenated_String := StrConcat(My_Array_Of_Strings, "\") 显然不起作用!

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!

那么,一个简单的问题:如何连接简单的字符串数组?

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

希望它也会帮助别人.

这篇关于如何在自动热键中连接字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆