Remove phone extension

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Remove phone extension

  • Creator
    Topic
  • #50011
    Gary Atkinson
    Participant

    Hi all-

    I have a receiving system that cannot handle a telephone extension and “dashes” sent in a IN1:7.  So for example, the engine receives (800)-555-1111X1234.  They only want to receive 1(800)5551111.  I was able to create some tcl code based on the “X” in the string.  But my code returns an empty string if “X” is not found in the phone number.  Here is my code:

    Code:

    lassign $xlateInVals num
    set a [ string first “X” $num]
    set newnum [string range $num 0 [ expr $a – 1 ] ]
    set xlateOutVals [ list $newnum ]

    What I like to do is look for both “X” or “x” and only send everything to the left of “X” or “x”.  I need to always remove the dashes.  I would to put this in a proc for reuse.  Any help, greatly appreciated  8)

Viewing 14 reply threads
  • Author
    Replies
    • #64511

      Here’s one way to do it …

      Code:

      set var “1(800)-555-1111X1234”
      regexp {^(.*?)[Xx].*$} $var match newVar
      regsub -all {-} $newVar {} newVar
      puts $newVar

      -- Max Drown (Infor)

    • #64512
      Charlie Bursell
      Participant

      Again, you take the longest road home.

      set num  [string map {- “”} [lindex $xlateInVals 0]]

      set xlateOutVals [ list $num ]

    • #64513
      Gary Atkinson
      Participant

      Thanks for the code!  I love regular expressions  ðŸ˜ˆ

      I just found out the vendor could process the extension before, but in their new code they can not now, surprise  ðŸ˜‰

    • #64514
      Kevin Kinnell
      Participant

      Charlie,

      Did you leave a ‘split’ or something out?  How were you getting rid of everything after the ‘X’ (or ‘x’) ?

      Maybe something like

      set num  [lindex [split [string map {- “”} [lindex $xlateInVals 0]] xX ] 0]

      set xlateOutVals [ list $num ]

      I dunno — the regexp looks pretty attractive — but then I’m JAPH…

      😉

      –kevin (keep ’em honest) kinnell

    • #64515
      Charlie Bursell
      Participant

      Huh, I’m cofused.  What X?

      Assume XlteInVals = 123-123-123

      And we *ALWAYS treat it as a list!

      set num  [string map {- “”} [lindex $xlateInVals 0]]

      echo $num

      > 123123123

      In fact one of the labs in my Level 3 class has you take a phome number of the type: (903) 452-6544 and return just numbers.  If you do it with a regular expression, I will give it back to you.

      string map

        $phoneNum

        String commands are *ALWAYS* more efficient than regular expressions since they are complied for a single purpose and optimized.

        There is no one that uses more regular expressions than I do but simple find/replace the string map, IMHO, is much more ergonomic.

    • #64516

      He needs to remove everything after the “X” or “x” in the phone number.

      From “(800)999-9999×0001” to “(800)9999999”.

      -- Max Drown (Infor)

    • #64517
      John Hamilton
      Participant

      Add a little before his string map will work.

      Something like

      set T_num [string toupper $IN_NUM]

      set  num [lindex [split $T_num X] 0]

      set out_num [string map {-“”} $num]

    • #64518

      Or use the regexp.  ðŸ˜‰

      -- Max Drown (Infor)

    • #64519
      Charlie Bursell
      Participant

      I thought his problem was to simply remove the dashes.  ðŸ˜•

      I guess I get in too big of a hurry sometimes.

      I stand by the statement about using regexp when string map would work

    • #64520
      Kevin Kinnell
      Participant

      Oh, I wouldn’t disagree with that at all, unless the same engine is running the regex and the tr (which could happen, but I’m pretty sure it doesn’t in Tcl.)

      Even so, I’ll bet a simple regex in a regsub command versus the tr (oh, okay…’string map’) is almost imperceptibly slower.  I think I’ll time 100K runs of removing everything from a 10 digit phone number with a very straightforward regexp or two versus the ‘string map’ and see how bad it is.  Spencer’s Tcl re engine is supposed to be as fast as it gets.

    • #64521
      Gary Atkinson
      Participant

      Thanks for all this discussion and this helps since I am a Tcl noobie  8)

      Since I have your’ll attention and ask another related Tcl question.  Is it possible to run a standard tcl proc (non-xltp) in a translation file? So for example if a had some tcl code that took out dashes, but it didn’t rely on using xlateInVals.

    • #64522
      Scott Lee
      Participant

      You could set it up as a pre or post proc to the Xlate.  To call it from the Xlate though it has to be an xltp proc.

    • #64523

      It’s possible I suppose, but I’m not sure why you would want to. Can you give an example?

      -- Max Drown (Infor)

    • #64524
      John Hamilton
      Participant

      Absoulte you can.

      There are any number of place you can modify the message contents.

    • #64525
      Jim Kosloskey
      Participant

      If the question is can you reference a Tps type proc from an Xlate and expect it to function, I think the answer is no.

      The Xlate can only reference xltp type procs and function properly.

      Jim Kosloskey

      email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

Viewing 14 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,126
Forums
28
Topics
9,297
Replies
34,440
Topic Tags
287
Empty Topic Tags
10