login | register
Sun 07 of Sep, 2008 [21:23 UTC]

voip-info.org

Discuss [0] History

Asterisk func cut

Created by: Corydon76,Last modification on Fri 08 of Feb, 2008 [17:12 UTC] by tcpip4000

Synopsis:

 CUT(varname,delimiter,fieldspec)
at least on asterisk 1.2.8 the parameters must be separated by "|" and not ","


Description:

 CUT(varname,delimiter,fieldspec)
 
  • varname: variable you want cut
  • delimiter: defaults to -
  • fieldspec: number of the field you want (1-based offset), may also be specified as a range (with -) or group of ranges and fields (with &).

Notes

  • The delimiter must be a single character. When multiple characters are specified, only the first character is used.
  • To specify a comma or semicolon as a delimiter, escape it with a backslash: CUT(foo,\,,1)
  • When multiple fields are specified, they are joined back together using the delimiter specified.
  • Leaving off one end of the range will give you the full variable at the field and to the other end of the variable.
    • "CUT(somevar,,3-)" would give the 3rd field and everything past,
    • "CUT(somevar,,-2)" would give the 2nd field and everything before.
  • This command is most useful when dealing with fields that are variable width. For fixed width string processing, use the builtin variable substitution.
  • CUT is frequently used to trim the uniqueid section off a channel name. For instance, the channel name might be SIP/somehost-f387 and you might want to trim that to SIP/somehost.
  • This function replaces the application Cut, which is now deprecated.

The varname parameter must be a variable name, not a string value. This is unusual syntax. So:


   exten => s,1,Set(foo=${CUT(bar,,2)})     ; This is correct syntax
   exten => s,1,Set(foo=${CUT(${bar},,2)})  ; This is invalid syntax (unless bar contains the name of another variable)

Return value

Returns the resulting string.

Example

 exten => s,1,Set(foo=1-2-3-4-5)
 exten => s,2,Set(foo=${CUT(foo,,1-3&5)})

foo is now set to 1-2-3-5

Cut a comma separated list:

 exten => s,1,Set(myVar="one,two,three")
 exten => s,2,Set(cutVar=${CUT(myVar|\,|1)})

cutVar is set to value 'one'

See also



Comments