Printkeys() To Array

Bob Sneidar bobs at twft.com
Fri Jan 20 16:37:57 EST 2012


I have an update. I didn't account for the fact that keys can be multiple words. This updated function should do the trick. 

function PKToArray thePrintKeys
    put 0 into theOldKeyCount
    put empty into theValue
    put the itemdelimiter into theOldDelim
    set the itemdelimiter to space
    
    repeat for each line theLine in thePrintKeys
        put the number of chars of theLine into count1
        put word 1 to -1 of theLine into theLine
        put the number of chars of theLine into count2
        put ((count1 - count2)) /5 +1 into theNewKeyCount
        
        put offset(":", theLine) into theChar
        if theChar <> 0 then
            put char theChar +2 to -1 of theLine into theValue
            put char 1 to theChar -1 of theLine into theKey
        else
            put theLine into theKey
        end if
        
        if theNewKeyCount >= theOldKeyCount then
            put "[" & theKey & "]" into item theNewKeyCount of theKeyList
        else
            put "[" & theKey & "]" into item theNewKeyCount to -1 of theKeyList
        end if
        
        if theChar <> 0 then
            put "put " & quote & theValue & quote & " into theNewArray" & theKeyList into theCommand
            do theCommand
            put empty into theValue
        end if
        
        put theNewKeyCount into theOldKeyCount
         
    end repeat
     
    set the itemdelimiter to theOldDelim
    return theNewArrayA
end PKToArray



More information about the use-livecode mailing list