Upgrade 3CX to v18 and get it hosted free!

Asterisk Func Cut

Author image

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 (and not a string – see PASSTHRU of Asterisk 1.8)
  • 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 Asterisk cmd 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


Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.