[asterisk-users] string length in dialplan
Leif Madsen
leif.madsen at asteriskdocs.org
Mon Feb 22 11:57:30 CST 2010
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 :)
Also, totally untested, I just wrote it in this email ;)
Leif Madsen.
http://leifmadsen.wordpress.com
More information about the asterisk-users
mailing list