Iterating over a list

From Etel

Jump to: navigation, search

Contents

Title

Iterating over a list

Problem

You have a list of comma-delimited items, such as a list of providers, and you want to run a certain set of steps, with each item.

Solution

Use the FIELDQTY and CUT dialplan functions to construct a loop:

exten => s,1,Set(mylist=one\,two\,three)
exten => s,n,Set(i=1)
exten => s,n,While($[${i} <= ${FIELDQTY(mylist,\,)}])
exten => s,n,Set(myitem=${CUT(mylist,\,,${i})
exten => s,n,...
exten => s,n,Set(i=$[${i} + 1])
exten => s,n,EndWhile

Discussion

While this is not the only type of loop that you can construct, the use of CUT, FIELDQTY, and SORT may be used in various applications for list manipulation and extraction of particular elements.

Note that the comma needs to be backslashed in extensions.conf, to protect it from being seen as an argument delimiter, instead of the character to delimit your list by.

See Also:

Metadata

  • By: TilghmanLesher
Personal tools