簡體   English   中英

如何在自動熱鍵中連接字符串數組

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

那些使用過的人都知道,自動化工具 AHK 是多么有用。

AHK 有 function StringSplit 或StrSplit()可以非常快速地將字符串拆分為數組元素。

如果您想操縱格式良好的字符串的某些部分,這非常有用,但不幸的是,似乎沒有辦法!

我花時間搜索,有一堆舊語法的樣本,這些樣本不起作用。 我想要的只是Final_Concatenated_String:= StrConcat(My_Array_Of_Strings, "\")這顯然不起作用!

所以,一個簡單的問題:如何連接簡單的字符串數組?

花費大量時間並找到不起作用的舊語法示例使我很難做到,以使其變得簡單。

將目錄拼接成字符串數組的簡單快速的解決方案:

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

更高級的版本,如果您在路徑字段中有結束反斜杠:

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]"\"
    }

在更深入的細節。 我需要從輸入字段復制目錄路徑,更改根目錄,將其粘貼回輸入字段並保存。

所以我最終得到了這個腳本:

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

希望它也會對某人有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM