[asterisk-users] string length in dialplan
Barry Miller
asterisk-users at notanet.net
Mon Feb 22 12:14:51 CST 2010
On Mon, Feb 22, 2010 at 12:57:30PM -0500, Leif Madsen wrote:
> Jerry Geis wrote:
> > I am trying to find out how I can tell the length of a string actually
> > CALLERID(num) in the dialplan.
> >
> > How is that done?
> >
> > If need to test the length of the CALLERID(num) if its less the 10 digits I
> > need to set it to a known value or insert 0's at the beginning until it
> > is 10 digits in length.
> > My PRI provider needs it set to 10 digits always.
>
> ...stuff before...
> exten => _NXXNXXXXXX,n,GoSub(set_cid,1())
> ...stuff after...
>
> exten => set_cid,1,NoOp()
> exten => set_cid,n,Set(CURRENT_CID_LENGTH=${LEN(${CALLERID(num)})})
> exten => set_cid,n,GotoIf($[${CURRENT_CID_LENGTH} = 10]?skip_modify_cid)
> exten => set_cid,n,While($[${LEN(${CALLERID(num)})} < 10])
> exten => set_cid,n,Set(CALLERID(num)=0${CALLERID(num)})
> exten => set_cid,n,EndWhile()
> exten => set_cid,n(skip_modify_cid),Return()
>
>
> There is likely a more efficient way of doing that, but I haven't gone through
> and looked at the functions to see if there might be a way of avoiding the loop :)
His provider wants 10 digits always, so
exten => set_cid,n,Set(FOO=0000000000${CALLERID(num)})
exten => set_cid,n,Set(CALLERID(num)=${FOO:-10})
would work, but in that case he's likely going to present annoying CIDs
like 0000000666 to his callees.
--
Barry
More information about the asterisk-users
mailing list