Iterating over a list
From Etel
Contents |
[edit]
Title
Iterating over a list
[edit]
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.
[edit]
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
[edit]
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.
[edit]
See Also:
[edit]
Metadata
- By: TilghmanLesher
