Asterisk {EXTEN} How to Add chars

i want to add Some CHars to EXTEN starting and in the middle
something like this
Exten=2111222
and i want to add “[” < this one in the start and in middle the number must be [2111]222 like this but i tried to add it in start but i got nothing can you help me ?

Please show how you tried to do it.

Also note that ${EXTEN} is a read only function that returns the value of a particular field in the channel data structure. It can only be modified indirectly.

if i make veriable for example NUMB=${EXTEN}
after that it will work?

Will what work? You still haven’t said what you tried.

same => n,Set(NUMB=${EXTEN})
same => n,Set([${NUMB})
in the start it is adding [ << this character and i want too add ] << this one after 4 digits and i can’t mannage how to add

If you know php you can do it with Substr function. And don’t know what are you trying to achieve but all can be handled by the PHP script and then return the value to the dialplan.

Your second Set is invalid.

There are probably many ways of doing it, but, unless “[” turns out to be special, you can use the standard sub-string notation that you can find in any sample dialplan, to pick out the various parts of the number, and then simply concatenate them, and the punctuation, in setting the variables.

I don’t think he needs to go to an external language for a simple problem like this.

exten => 502,1,NoOP()
 same => n,Set(MyString=2111222)
 same => n,Set(MyString=[${MyString})
 same => n,NoOP(MyString is ${MyString})
 same => n,Set(MyHalf=${LEN(${MyString})})
 same => n,Set(MyHalf=${MATH(${MyHalf} / 2,i)})
 same => n,NoOP(MyHalf is ${MyHalf})
 same => n,Set(MyString=${MyString:0:${MyHalf}}]${MyString:${MyHalf}})
 same => n,NoOP(MyString is ${MyString})
 same => n,Hangup()

If I cared more I could probably do this more efficiently.

1 Like