1. Re: Constructing an array value continued
--Here's my spin on the array value thing. Enjoy.
--Steve Elder
function get_field(object number, sequence label)
atom comma_count,control
sequence item
comma_count = 0
control = 0
item = {}
if compare(label[1],',') > 0 or compare(label[1],',') < 0 then
label = ',' & label
end if
for i = 1 to length(label) do
if compare(label[i],',') = 0 then
comma_count = comma_count + 1
end if
if compare(comma_count,number) = 0 then
control = 1
elsif compare(comma_count,number) = 1 then
control = 2
end if
if control = 1 then
item = item & label[i]
end if
end for
return item[2..length(item)]
end function
-- examples
sequence my_data,my_data2,filter
my_data2 = {}
my_data = "dog ,beagle ,spaniel ,shepherd ,large ,small ,colors ,black
,white ,"
puts(1,get_field(4+1,my_data)) -- large as subset of shepherd
puts(1,get_field(4+2,my_data)) -- small as subset of shepherd
-- constructing a new data object
puts(1,"\nconstructing a new data object\n")
filter = {1,2,3,4,4+1,4+2,7,8,9,1} -- determines which fields to keep
for i = 1 to length(filter) do
my_data2 = my_data2 & get_field(filter[i],my_data)
end for
puts(1,my_data2)