Manipulating Dialplan Variables : Asterisk

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.


Related Posts

  • 54
    Asterisk can make use of global, shared and channel-specific variables for arguments to commands. Variables are referenced in the dialplan (extensions.conf) using the syntax ${foo:offset:length} where foo is the name of the variable, offset is an optional field indicating which characters should be excluded, and length is an optional field indicating the number of characters from…
    Tags: variable, variables, asterisk, $
  • 54
    Dialplan Introduction:  
    Tags: dialplan, asterisk
  • 38
    Contexts Dialplans are broken into sections called contexts. Contexts are named groups of extensions, which serve several purposes. 1. Contexts keep different parts of the dialplan from interacting with one another. 2. An extension that is defined in one context is completely isolated from extensions in any other context, unless interaction is specifically…
    Tags: dialplan, asterisk
  • 35
    JavaScript Variable Scope The scope of a variable is the region of your program in which it is defined. JavaScript variables have only two scopes. Global Variables− A global variable has global scope which means it can be defined anywhere in your JavaScript code. Local Variables− A local variable will…
    Tags: variable, variables
  • 33
    Welcome to the C Knowledge Base and Tutorial   Introduction to C Programming Start Learning C Programming What is C? Why We should learn C C Character Set : Constants, Variables and Keywords Constant and Variable in C: C Keywords: Types of C Constant Rules for Constructing Integer Constants Rules…
    Tags: variable, variables, set

Leave a Reply

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

%d bloggers like this: