title: Replace characters in Asterisk Dialplan
body: <p>I want to change a couple off characters * # for A and P to have the monitor filename with characters more friendly. The only solution I could find was to do it my self within the dialplan but it generates a lot of verbosity output and is not as efficient(fast) as I would like to. I'll post it here just in case someone wants to use it. But I'm looking for an asterisk function that I can compile something that I can call withing the dialplan like ${REPLACE(${EXTEN},*,a)} and have the exten **123**456*** converted to AA123AA456AAA.</p>
  
  <pre><code>;
  ; MACRO REPLACE
  ;
  [macro-replace]
  ;
  ;   ${ARG1} - String source
  ;   ${ARG2} - Chars to replace
  ;   ${ARG3} - Chars to replace with
  ;
  exten =&amp;gt; s,1,NoOp(Replacing ${ARG2} for ${ARG3} in ${ARG1})
  exten =&amp;gt; s,n,Set(str=${ARG1})
  exten =&amp;gt; s,n,Set(find=${ARG2})
  exten =&amp;gt; s,n,Set(replace=${ARG3})
  exten =&amp;gt; s,n,Set(i=0)
  exten =&amp;gt; s,n,Set(length=${LEN(${str})})
  exten =&amp;gt; s,n,While($[${i} &amp;lt; ${length}])
  exten =&amp;gt; s,n,GotoIf($["${str:${i}:1}" != "${find}"]?continue)
  exten =&amp;gt; s,n,Set(pre=)
  exten =&amp;gt; s,n,GotoIf($["${i}" = "0"]?post)
  exten =&amp;gt; s,n,Set(pre=${str:0:${i}})
  exten =&amp;gt; s,n(post),Set(post=)
  exten =&amp;gt; s,n,GotoIf($["${i}" = $[${length} - 1]]?write)
  exten =&amp;gt; s,n,Set(post=${str:$[${i} + 1]})
  exten =&amp;gt; s,n(write),Set(str=${pre}${replace}${post})
  exten =&amp;gt; s,n(continue),Set(i=$[${i} + 1])
  exten =&amp;gt; s,n,EndWhile
  exten =&amp;gt; s,n,Set(REPLACERESULT=${str})
  </code></pre>
  
  <p></p></p>