11-05-2006, 05:48 PM
This example uses type.
This example uses 2-dim array.
;str logfiledata.getfile(...)
str logfiledata=
;header
;
;not urgent a b c d e
;urgent a b c d e
;urgent a b c d e
;not urgent a b c d e
;urgent a b c d e
;
;
;
;not urgent a b c d e
;urgent a b c d e
;urgent a b c d e
;not urgent a b c d e
;urgent a b c d e
;
type X765 str'u str'a str'b str'c str'd str'e ;;declare type to hold 6 words
ARRAY(X765) a
str s
foreach s logfiledata
,if(!s.len) continue
,if(!s.begi("urgent")) continue
,X765& e=a[a.redim(-1)] ;;add 1 new element and get reference to it
,if(tok(s &e.u 6 " ")!=6) end "bad format"
,out "%s, %s, %s, %s, %s, %s" e.u e.a e.b e.c e.d e.e
,This example uses 2-dim array.
;str logfiledata.getfile(...)
str logfiledata=
;header
;
;not urgent a b c d e
;urgent a b c d e
;urgent a b c d e
;not urgent a b c d e
;urgent a b c d e
;
;
;
;not urgent a b c d e
;urgent a b c d e
;urgent a b c d e
;not urgent a b c d e
;urgent a b c d e
;
ARRAY(str) a.create(6 0) ;;first dimension has 6 elements, one for each word; second dimension is resizable. Imagine that first dimension is horizontal (x), second vertical (y).
str s
foreach s logfiledata
,if(!s.len) continue
,if(!s.begi("urgent")) continue
,int ni=a.redim(-1) ;;add 1 new element (6-string array) in second dimension
,if(tok(s &a[0 ni] 6 " ")!=6) end "bad format"
,out "%s, %s, %s, %s, %s, %s" a[0 ni] a[1 ni] a[2 ni] a[3 ni] a[4 ni] a[5 ni]
,