Next Previous Contents

33. extract_element

Synopsis

Extract the nth element of a string with delimiters

Usage

String_Type extract_element (String_Type list, Integer_Type nth, Integer_Type delim);

Description

The extract_element function may be used to extract the nth element of the delim delimited list of strings list. The function will return the nth element of the list, unless nth specifies more elements than the list contains, in which case NULL will be returned. Elements in the list are numbered from 0.

Example

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;
     }
See Also

is_list_element, is_substr, strchop, create_delimited_string


Next Previous Contents