pulling a specific phone number

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library pulling a specific phone number

  • Creator
    Topic
  • #51573
    Kevin Crist
    Participant

    I need to pull a field from a segmen with multiple phone numbers. i need to search for one and put it in front using tcl.

    Example: This is field 10 of an STF segment.

    |(888)451-3636CH~(812)887-4356CC~(747)787-0000CO~(812)884-8585CF~666CB~|

    What i am wanting: ~(747)787-0000CO~(812)887-4356CC~(888)451-3636CH~(812)884-8585CF~666CB~|

    The recieving system only takes the first number in the field and populates that number in its office phone number location. But that number isnt always the first number. It is the number witht he CO at the end. How can i search through the numbers and find the one with the CO if it exists and put it in the first position?

    Here is what i have so far to pull out the phone fields:

    set phone [lindex [split [lindex $STFList $STFPhoneNum] $repSep] 0]

    Thanks for any help.

Viewing 2 reply threads
  • Author
    Replies
    • #70813
      Chris Williams
      Participant

      Kevin,

      You want to iterate through the repetitions of the field, and for each one of them test whether it contains “CO”. If it does, then write the value out to the destination. If it doesn’t, don’t do anything. Go on to the next repetition.

    • #70814
      Charlie Bursell
      Participant

      As stated you could maybe do this in Xlate.  But if you want to do in Tcl

      I’m a little confused as to what you want.  Do you want to simply move the number to the front or replace what is in front with the number?

      Assume you want to simply move number to front.  Assume you have extracted the field to variable fld

      set lst [split $fld $repSep]

      set loc [lsearch -regexp $lst {CO$}]

      if {$loc >= 0} [

          set CO [lvarpop lst $loc]

          set fld [concat $CO $lst]

      }

      set fld [join $fld $repSep]

      If you want to replace first element with number then change

          set fld [concat $CO $lst]

      to

          set fld [lreplace $lst 0 0 $CO]

    • #70815
      Jim Kosloskey
      Participant

      Kevin,

      This could be done in an Xlate as Chris indicated or in Tcl as Charlie indicated.

      If you are using an Xlate you may need some Tcl. If you are on Cloverleaf 5.6 or later you won’t need Tcl to test for the CO (assuming it can only occur once in each iteration) as I think the new contains (ct) string oerand will do the trick.

      However if you want to take some portion of the telephone number then you will probably need some tcl for that.

      Of course if the provider of the message had followed the standard (I am assuming version 2.3 or later) then this XTN data type for Phone should have had all the pieces of the telephone number (including the identifier of type of phone – which I assume the CO is) in their proper components and then you would probably not need any Tcl in the Xlate.

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

Viewing 2 reply threads
  • The forum ‘Tcl Library’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,129
Forums
28
Topics
9,301
Replies
34,447
Topic Tags
288
Empty Topic Tags
10