Manipulating Dialplan Variables : Asterisk

Rate this post

We often require to do string manipulation on a variable. For example, a variable named phonenumber which represents a number we’d like to call, and we want to strip off the first 5 digit before dialing the number. Asterisk provides a special syntax for doing just that, which looks like


The optional skip field tells Asterisk how many digits to strip off the front of the value. For example, if phonenumber were set to a value of 64579899338979, then ${phonenumber:2}would tell Asterisk to remove the first two digits and return 579899338979.

If the skip field is negative, Asterisk will instead return the specified number of digits from the end of the number. As an example, if phonenumber were set to a value of 64579899338979, then ${phonenumber:-2} would tell Asterisk to return the last two digits of the variable, or 79.

If the optional length field is set, Asterisk will return at most the specified number of digits. As an example, if phonenumber were set to a value of 64579899338979, then ${phonenumber:0:3} would tell Asterisk not to skip any characters in the beginning, but to then return only the three characters from that point, or 645. By that same token, ${phonenumber:1:3} would return 457.


For any query or issue, feel free to discuss on

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: