Re: [asterisk-users] Cut off last character of EXTEN

2013-08-20 Thread A J Stiles
On Tuesday 20 August 2013, Pat Collins wrote:
> From: asterisk-users-boun...@lists.digium.com
> [mailto:asterisk-users-boun...@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.

--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Cut off last character of EXTEN

2013-08-20 Thread Pat Collins
From: asterisk-users-boun...@lists.digium.com
[mailto:asterisk-users-boun...@lists.digium.com] On Behalf Of Steven Howes
Sent: Tuesday, August 20, 2013 7:38 AM
To: Asterisk Users Mailing List - Non-Commercial Discussion
Subject: Re: [asterisk-users] Cut off last character of EXTEN

 

 

On 20 Aug 2013, at 12:25, Pat Collins wrote: 

Here ya go:

 

112233# use ${EXTEN:0:6})

123# use ${EXTEN:0:3})

123456789# use ${EXTEN:0:9})

 

I think 'variable length' implied 'unknown length'...

 

S

 

Yea, I realized that after I replied

Got ahead of myself again.

That was the only way I was able to get rid of the '#' tho

--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Cut off last character of EXTEN

2013-08-20 Thread Steven Howes

On 20 Aug 2013, at 12:25, Pat Collins wrote: 
> Here ya go:
>  
> 112233# use ${EXTEN:0:6})
> 123# use ${EXTEN:0:3})
> 123456789# use ${EXTEN:0:9})

I think 'variable length' implied 'unknown length'...

S--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Cut off last character of EXTEN

2013-08-20 Thread Pat Collins
From: asterisk-users-boun...@lists.digium.com
[mailto:asterisk-users-boun...@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})

 

--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Cut off last character of EXTEN

2013-08-20 Thread jg

Damn it!

Try: "${EXTEN:0:-1}"

jg

--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
  http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
  http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Cut off last character of EXTEN

2013-08-20 Thread Jonas Kellens

On 08/20/2013 10:40 AM, Gareth Blades wrote:

On 20/08/13 09:29, Jonas Kellens wrote:

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.


Set(variable=${EXTEN:0:$[LEN(${EXTEN})-1]})


Hello,

this works !

Thanks.

Jonas.
--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Cut off last character of EXTEN

2013-08-20 Thread Łukasz Grzywański
Hi,
try

[testEx]
exten => _X.,1,noop(${EXTEN})
same => n,noop(len: ${LEN(${EXTEN})})
same => n,noop(${EXTEN:0:${MATH(${LEN(${EXTEN})}-1)}})
exten => _X.,n,hangup



On 20 August 2013 12:15, Jonas Kellens  wrote:

>  On 08/20/2013 10:47 AM, jg wrote:
>
> How about "${EXTEN:-1:1}"?
>
> "The Definitive Guide" has a special paragraph with the title "*More
> Advanced Digit Manipulation".*
>
> jg
>
>
>
> Same result : #
>
>
> Jonas.
>
> --
> _
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
> New to Asterisk? Join us for a live introductory webinar every Thurs:
>http://www.asterisk.org/hello
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>http://lists.digium.com/mailman/listinfo/asterisk-users
>
--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Cut off last character of EXTEN

2013-08-20 Thread Jonas Kellens

On 08/20/2013 10:47 AM, jg wrote:

How about "${EXTEN:-1:1}"?

"The Definitive Guide" has a special paragraph with the title "*More 
Advanced Digit Manipulation".*


jg



Same result : #


Jonas.
--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Cut off last character of EXTEN

2013-08-20 Thread jg

How about "${EXTEN:-1:1}"?

"The Definitive Guide" has a special paragraph with the title "*More Advanced Digit 
Manipulation".*

jg
--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Cut off last character of EXTEN

2013-08-20 Thread Gareth Blades

On 20/08/13 09:29, Jonas Kellens wrote:

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.


Set(variable=${EXTEN:0:$[LEN(${EXTEN})-1]})

--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

[asterisk-users] Cut off last character of EXTEN

2013-08-20 Thread Jonas Kellens

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.
--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users