The expression
extract_element ("element 0, element 1, element 2", 1, ',')
returns the string " element 1", whereas
extract_element ("element 0, element 1, element 2", 1, ' ')
returns "0,".
The following function may be used to compute the number of elements
in the list:
define num_elements (list, delim)
{
variable nth = 0;
while (NULL != extract_element (list, nth, delim))
nth++;
return nth;
}
Alternatively, the strchop function may be more useful. In
fact, extract_element may be expressed in terms of the
function strchop as
define extract_element (list, nth, delim)
{
list = strchop(list, delim, 0);
if (nth >= length (list))
return NULL;
else
return list[nth];
}
and the num_elements function used above may be recoded more
simply as:
define num_elements (list, delim)
{
return length (strchop (length, delim, 0));
}