You should probably look at CSV functions, since AHK has more support for that format.
Here's an old one that could use an update. It's a lookup function designed to work with tables with columns both separated and padded with spaces. How about you clean it up and repost the newer version?
Code:
MyTable =
(
0 A B C D E
1 red green blue orange blue
2 green red blue green red
3 purple green red blue orange
... ... ... ... ... ...
999 green green blue purple blue
)
row = 999
col = D
MsgBox % LookUp( MyTable, row, col, "`n `r" )
LookUp( data, row="total", col=0, delimiters="`n, `r`t" )
{
; data = a table of data, rows are separated by the first character in 'delimiters'
; and columns are separated by *one or more of* the second character in 'delimiters'.
;
; row = the numerical index of the desired row. If the first column contains
; an integer, it will be used as both the row index and as the first column.
; use an empty string in 'row' to obtain an entire column. Use the keyword
; 'total' in this parameter to get the raw number of rows in the table
;
; col = the index or alias of the desired column. When using an alias, the topmost
; row in 'data' should contain the aliases for each column in order. Also, when using
; an alias, the topmost row's index is considered to be 0 unless the first column
; contains an integer. Use the keyword 'total' in this parameter to get the raw
; number of columns in the *first* row (a table's columns shouldn't differ row-by-row)
;
; delimiters = a string of two or more characters. The first characters defines
; the delimiter separating rows in the data table. The second character defines
; the delimiter separating columns in the data table. Other characters define
; characters which will be dropped from the beginning and end of any row or column.
If row = total
{
StringSplit, data, data, % Chr(2), %delimiters%
StringReplace, data1, data1, % SubStr(delimiters, 1, 1),, UseErrorLevel
return ErrorLevel
}
Else If col = total
{
Loop, Parse, data, % SubStr(delimiters, 1, 1), % d2 := SubStr(delimiters, 2, 1)
If (data1 := A_LoopField) != ""
break
Loop
{
StringReplace, data1, data1, %d2%%d2%, %d2%, All
If ErrorLevel
break
}
StringReplace, data1, data1, %d2%,, UseErrorLevel
return ErrorLevel+1
}
Else Loop, Parse, data, % d1 := SubStr(delimiters, 1, 1), % d2 := SubStr(delimiters, 2, 1)
{
StringSplit, data, A_LoopField, % Chr(2), %delimiters%
If !(Thisrow := data1)
continue
Loop
{
StringReplace, thisrow, thisrow, %d2%%d2%, %d2%, All
If ErrorLevel
break
}
If !col0
If col is NOT number
{
If !InStr( d2 . thisrow . d2, d2 . col . d2 )
Return "Error: invalid column"
StringSplit, col, thisrow, %d2%
RowNum = 0
Loop, %col0%
If col%A_Index% = %col%
{
col = %A_Index%
break
}
}
Else
{
RowNum = 1
StringReplace, thisrow, thisrow, %d2%, %d2%, UseErrorLevel
col0 := ErrorLevel + 1
If col0 < %Col%
Return "Error: column not present"
}
StringLeft, SelfIndex, Thisrow, % InStr(Thisrow, d2) - 1
If SelfIndex is integer
rownum := SelfIndex
If row = %rownum%
If col
{
StringSplit, data, thisrow, %d2%, % SubStr(delimiters, 3)
return data%col%
}
else
return thisrow
else If !row
If col
{
StringSplit, data, thisrow, %d2%, % SubStr(delimiters, 3)
cdata .= d1 . data%col%
}
rownum++
}
return SubStr(cdata, 2)
}