[asterisk-users] Cut off last character of EXTEN

A J Stiles asterisk_list at earthshod.co.uk
Tue Aug 20 07:04:37 CDT 2013


On Tuesday 20 August 2013, Pat Collins wrote:
> From: asterisk-users-bounces at lists.digium.com
> [mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of Jonas Kellens
> Sent: Tuesday, August 20, 2013 4:29 AM
> To: Asterisk Users Mailing List - Non-Commercial Discussion
> Subject: [asterisk-users] Cut off last character of EXTEN
> 
> 
> 
> Hello,
> 
> how can I cut off the last character of the EXTEN-variable with variating
> length ?
> 
> So I have :
> 
> 112233#
> 123#
> 123456789#
> 
> I want to cut off the last character.
> 
> ${EXTEN:-1} gives me #, but that is the character I want to cut off.
> 
> 
> 
> Kind regards,
> Jonas.
> 
> 
> 
> Here ya go:
> 
> 
> 
> 112233# use ${EXTEN:0:6})
> 
> 123# use ${EXTEN:0:3})
> 
> 123456789# use ${EXTEN:0:9})

Yes; but the whole point is, the original poster does not know the length of 
the number in the first place!


What is needed is
${EXTEN:0:-1}
which will skip no digits from the beginning, and use all but one digit of the 
remainder.


Now, here's my handy cut-out-and-keep guide to the syntax for the implied 
substring method in Asterisk dialplan:

Write
${VARIABLE:skip}
to skip some characters and use everything else, or
${VARIABLE:skip:show}
to skip some characters and only use part of the remainder.  And a minus sign 
means "all but".  Some recipes, by way of example;

When dealing with international calls,
${EXTEN:2}
will remove the "00" from the beginning  (skip 2 digits).

When routing direct dial-in numbers,
${EXTEN:-3}
gets the last 3 digits of the dialled number  (skip all but 3 digits).

If the number allocation has been crafted carefully so that  (for argument's 
sake)  numbers in the range 100 - 199 are management and accounts, 200 - 299 
are sales, 300 - 399 are purchasing, 400 - 499 are IT and buildings 
maintenance and 500 - 599 are factory floor, then
${EXTEN:-3:1}
will indicate the department  (skip all but 3, and use only the first digit).  
You could also write ${EXTEN:-3:-2}  (skip all but 3, and use all but 2 of the 
remainder)  but since you already know the length anyway, this is probably a 
little pointless.

To remove both a dialled "9" from the beginning and a terminating comment mark 
from the end  (skip one and use all but one)  then the required syntax would 
be
${EXTEN:1:-1}


-- 
AJS

Answers come *after* questions.



More information about the asterisk-users mailing list