How to return and use result of StringSplit? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DRPS

How to return and use result of StringSplit?

27 Aug 2016, 14:42

I am reading the contents of a file that I drag onto my AHK script to extract some data from it. All of that works fine, the ArgumentsArray in the ExtractAction contains all the data I want at the end of the function but when I want to use the returned data of the method it says it's size is 2 but when I want to access the data it is empty.

Here is the code.

Code: Select all

ExtractAction(Action, Contents) {
    RegExMatch(Contents, "%Action%((.*))", ActionResult)
    RegExMatch(ActionResult, "\((.*?)\)", parenthesis)

    StringReplace, parenthesis, parenthesis, (, ``, All
    StringReplace, parenthesis, parenthesis, ), ``, All

    StringSplit, ArgumentsArray, parenthesis, `,`

    Loop, %ArgumentsArray0%
    {
        ArgumentsArray%a_index% := RemoveInvalidCharacters(ArgumentsArray%a_index%)
    }

    MsgBox, %ArgumentsArray0% ; ArgumentsArray0 size is 2, ArgumentsArray1 and ArgumentsArray2 contain what I want

    return %ArgumentsArray0%
}

Loop %0% {
    GivenPath := %A_Index%

    Loop %GivenPath%, 1
        FilterFile = %A_LoopFileFullPath%

    FileRead, Contents, %FilterFile%

    result := ExtractAction("ActionName", Contents) ; result will be ArgumentsArray0

    MsgBox, %result1% ; result0 size is 2, result1 and result2 are empty
}
foxhunter
Posts: 72
Joined: 04 Aug 2016, 04:27

Re: How to return and use result of StringSplit?  Topic is solved

27 Aug 2016, 17:39

Don't use pseudo arrays for function returns.

Code: Select all

ExtractAction(Action, Contents) {
    RegExMatch(Contents, "%Action%((.*))", ActionResult)
    RegExMatch(ActionResult, "\((.*?)\)", parenthesis)

    StringReplace, parenthesis, parenthesis, (, ``, All
    StringReplace, parenthesis, parenthesis, ), ``, All

    StringSplit, ArgumentsArray, parenthesis, `,`
    myarray:=[]

    Loop, %ArgumentsArray0%
    {
        myarray[a_index] := RemoveInvalidCharacters(ArgumentsArray%a_index%)
    }

    msgbox % myarray[0] "`n" myarray.1 "`n" myarray.2

    return myarray
}
result:=[]

Loop %0% {
    GivenPath := %A_Index%

    Loop %GivenPath%, 1
        FilterFile = %A_LoopFileFullPath%

    FileRead, Contents, %FilterFile%

    result := ExtractAction("ActionName", Contents) 

    MsgBox, % result.0 "`n" result.1 "`n" result.2 
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Descolada, Rohwedder, Rxbie and 160 guests