• News
  • Idefisk
  • Tools
  • Tutorials
  • Forum
  • Reviews
  • VoIP Providers
  • Archives
  • Gallery
ZOIPER SIP softphone
Back to Tutorials

6.1.2.93. SubString (dialplan application)

1. SubString - this application allows you to save sub-stringed digits in a given variable.

NOTE: This application is valid for Asterisk version 1.0.9 and above.

 


Syntax:

This application is deprecated, so in order to obtain similar result, please use the following syntax:

Set(NewVar=${variable:digit1:digit2})

 


List with the possible options

digit1 - this argument shows from where the reading of the value to start: from left to right or from the right to left. Also it shows from which digit to start. If the digit is positive the reading will start from the beginning. If the digit is negative then the reading will start from the end of the value.
digit2 - this argument shows how many digits to be read.

 


Purpose and usage

This application will read the value of the variable and then according to the specified digits, it will take some of the letters or digits from the value and it will store them in a new variable.

Below, we will give you an example.

 


Prerequisites

To use this application you need a working Asterisk PBX with registered users in iax.conf, sip.conf or mgcp.conf(It depends on which protocol you would like to use) and made extensions.

To see how the application works we recommend to use our IAX softphone Idefisk. You can download it from here. Please also read our tutorial to learn how to configure it to work with Asterisk PBX.

 


Asterisk PBX configurations

NOTE: This is only an example of what for you can use this application. Of course you can use it and for other things.


iax.conf Configurations

We need one registered user in iax.conf file. This is because we are going to use the IAX2 protocol. If you want to use other protocol such as SIP or MGCP, you have to do the configurations below respectively in sip.conf or mgcp.conf.

iaxoneuser.jpg

So, we have registered the user user1

Type=friend means that this user can make and receive calls. Host=dynamic means that the IP is not static but dynamic through a DHCP server. Allow=all means that the line which this user will use, could support all audio codecs. Context=test - this shows that this user is working with the extensions in this context of the configuration file extensions.conf.


extensions.conf Configurations

extsubstring.jpg

On the picture above you can see our extensions.conf file.

In our example when somebody dials 1111, the call will be answered by the Answer application. The next executed extension, will be the one which contains the Set application. Thanks to it, we will set the following value: 0123456789 - to the variable test.

The next executed extension also contains the Set application. However, here as arguments in the brackets we will set the following: ASD=${test:-2:2}. What would be the effect of this extension? The variable test will be read. -2 means, that we will start from the end of the value and we will read it to the left. 2 means that we will read the first two digits from the left and they will be stored in a new variable. In our case this variable is ASD.

We will use the NoOp application to check the result from the previous operations. The extension with priority 4 will show us the value of the ASD variable. In our case it is 89. These are exactly the last two digits from the value of the test variable. So the operation is successful.

In order to be sure that the Asterisk PBX will hang up the line after the conversation is over, it is a good idea to make an extension for hanging up the line.

 


2. Screenshots of what you can see on the CLI of the Asterisk PBX

clisubstring.jpg


 


3. Additional information

For more information about extensions.conf you can check here.
For more information about iax.conf you can check here.

This application is tested with our IAX softphone Idefisk. You can download it from here. For more information about this softphone please read our tutorial.

If you would like to test this application with the SIP channel you can read our tutorials about the SIP Softphones to learn how to configure them to work with Asterisk PBX

 


4. Uploaded files

iax.conf
extensions.conf

 

 
User Comments
Anonymous (anonymous at somewhere dot com)
24 March 2006 05:37:21
Note that the for the starting position (digit1), the first position is 0 not 1, so:

;78 test substring function
exten => 78,1,Answer()
exten => 78,n,Set(test=56789)
exten => 78,n,Set(str=${test:1:2})
exten => 78,n,NoOp(str = ${str})
exten => 78,n,SayDigits(${str})
exten => 78,n,Wait(3)
exten => 78,n,Hangup()

The result is: 67 not: 56
 
Add Comment
Name:
Email:
Comment:
In order to prevent automatic posting on our website, we kindly request you to type in the number you see in the picture below.
Image Verification:
 

Latest Headlines:

  • T.38 faxing with Zoiper 2.15 is now easier than ever
    section: voip software
  • Asterisk 1.4.21 Released
    section: Asterisk
  • Asterisk 1.4.20 Released
    section: Asterisk
  • Asterisk 1.4.20-rc2 Released
    section: Asterisk
  • Asterisk 1.4.20-rc1 Now Available
    section: Asterisk
  • News Archives (older news)

Latest Tutorials:

  • VMAuthenticate (dialplan application)
    added 01/Mar/2008 15:57
  • Siptronic ST-530
    added 06/Nov/2007 17:57
  • Siemens C455 IP hardphone
    added 05/Nov/2007 10:24
  • Zoiper
    added 22/Oct/2007 17:53
  • Grandstream GXP-2020
    added 15/Oct/2007 18:17

Latest Comments:

  • i agry ur sip dialar ...
    tutorial: Idefisk - IAX2 softphone
  • It happened that a Dog <a href="http://w...
    section: voip hardware
  • It happened that a Dog <a href="http://w...
    section: voip hardware
  • thinks i installation <A href=\"http:...
    tutorial: Installation on CentOS
  • uh, why not just use the asterisk packag...
    tutorial: Installation on Debian
 
contact us at: support@asteriskguru.com - asterisKGuru.com © all rights reserved   |   *asterisk is registered trademark of © Digium™