RELATED TAGS
The indexed nature of sequence variables makes it easy to access elements. This is because with these indexes, we can specifically pick out single or multiple elements in the sequence.
The extract()
method uses the index of sequences to pick out elements from them. This method will accept a sequence with the indexes of elements that would be extracted from another sequence and returned.
For example, if we have a sequence A = "This is sports"
and the sequence of indexes whose elements we wish to extract as B = {1,2,10,11}
. The output will be a sequence C = {Thpo}
.
extract(source,index_list)
source
: This is the sequence from which values will be extracted.
index_list
: This sequence contains a list of indexes that can be found in source
whose values will be extracted.
This method returns a sequence value whose length is the same as the length of index_list
.
Note: We can extract a particular item from the
source
multiple times by repeating its index inindex_list
. The returned sequence has items arranged in the same manner as the element’s index inindex_list
.
include std/sequence.e sequence source1, source2, result1, result2 source1 = {5,6,7,8,9,10} source2 = "This is sports" result1 = extract(source1 ,{4,5,3}) result2 = extract(source2,{1,2,10,11}) puts(1, "This is extracted from source1: ") print(1,result1) printf(1, "\nThis is extracted from source2: %s",{result2})
extract()
method.extract()
to the result1
and result2
variables.RELATED TAGS
CREATOR
View all Courses