Thank you for your reply.
I did a test ... your solution works to remove the zero columns
Code: Select all
;q:: ;remove blank rows
oArray := [[0, 0, 0, 0, 0]
, [0, 2, 0, 2, 0]
, [0, 0, 0, 0, 0],
, [0, 4, 0, 4, 0]
, [0, 0, 0, 0, 0]]
PrintTable(oArray, showgui:=false, comment_header:="input", comment_footer:="row 4 of the index is missing >> 1,2,3, ? ,5,6")
Loop, % vIndex := oArray.Length()
{
vIsEmpty := 1
for vKey, vValue in oArray[vIndex]
if vValue
{
vIsEmpty := 0
break
}
if vIsEmpty
oArray.RemoveAt(vIndex)
vIndex--
}
;MsgBox, % JEE_ObjList(oArray)
vOutput := ""
for vKey, oValue in oArray
{
for vKey2, vValue2 in oValue
vOutput .= vValue2 " "
vOutput := SubStr(vOutput, 1, -1) "`r`n"
}
PrintTable(oArray, showgui:=false, comment_header:="remove blank rows", comment_footer:="ok")
;MsgBox, % vOutput
;return
;==================================================
;w:: ;remove blank columns (known column count)
oArray := [[0, 0, 0, 0, 0]
, [0, 2, 0, 2, 0]
, [0, 0, 0, 0, 0],
, [0, 4, 0, 4, 0]
, [0, 0, 0, 0, 0]]
;identify blank columns
oEmpty := [], vColCount := 5
Loop, % vColCount
oEmpty.Push(1)
for vKey, oValue in oArray
for vKey2 in oEmpty
if oValue[vKey2]
oEmpty.Delete(vKey2)
;remove blank columns
if oEmpty.Length()
{
oEmpty2 := []
Loop, % vIndex := oEmpty.Length()
if oEmpty.HasKey(vIndex--)
oEmpty2.Push(vIndex+1)
for vKey, oValue in oArray
for vKey2 in oEmpty2
oValue.RemoveAt(vKey2)
}
PrintTable(oArray, showgui:=false, comment_header:="remove blank columns (known column count)", comment_footer:="Ok")
;MsgBox, % JEE_ObjList(oArray)
vOutput := ""
for vKey, oValue in oArray
{
for vKey2, vValue2 in oValue
vOutput .= vValue2 " "
vOutput := SubStr(vOutput, 1, -1) "`r`n"
}
;MsgBox, % vOutput
;return
;==================================================
;e:: ;remove blank columns (unknown column count)
oArray := [[0, 0, 0, 0, 0]
, [0, 2, 0, 2, 0]
, [0, 0, 0, 0, 0],
, [0, 4, 0, 4, 0]
, [0, 0, 0, 0, 0]]
;identify blank columns and get column count
oEmpty := [], vMax := 0
for vKey, oValue in oArray
{
Loop, % oValue.Length() - vMax
vMax += 1, oEmpty[vMax] := 1
for vKey, oValue in oArray
for vKey2 in oEmpty
if oValue[vKey2]
oEmpty.Delete(vKey2)
}
vColCount := vMax
;remove blank columns
if oEmpty.Length()
{
oEmpty2 := []
Loop, % vIndex := oEmpty.Length()
if oEmpty.HasKey(vIndex--)
oEmpty2.Push(vIndex+1)
for vKey, oValue in oArray
for vKey2 in oEmpty2
oValue.RemoveAt(vKey2)
}
;MsgBox, % JEE_ObjList(oArray)
vOutput := ""
for vKey, oValue in oArray
{
for vKey2, vValue2 in oValue
vOutput .= vValue2 " "
vOutput := SubStr(vOutput, 1, -1) "`r`n"
}
PrintTable(oArray, showgui:=true, comment_header:="remove blank columns (unknown column count)", comment_footer:="OK")
;MsgBox, % vOutput
return
;https://autohotkey.com/board/topic/94749-creating-a-matrix/
PrintTable(table, showgui:=false, comment_header:="", comment_footer:="")
{
for RowIndex, Row in table
{
temp :=" ["
for ColumnIndex, Column in Row
temp .= Column ", "
output .= SubStr(temp, 1, strlen(temp)-1) "]" a_space a_space RowIndex "`n"
}
Msgbox % SubStr(output, 1, strlen(output)-1)
gui 99: font,s10, consolas
gui 99: add, text,w300, % comment_header
gui 99: add, edit,w300, % SubStr(output, 1, strlen(output)-1) ""
gui 99: add, text,w300, % comment_footer
gui 99: +resize
gui, color
if (showgui){
gui 99: show
sleep, 10
send, {down}
}
}