lsearch and split help please

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf lsearch and split help please

  • Creator
    Topic
  • #54774
    Femina Jaffer
    Participant

      Can someone help with the following?

      I need to find the “MI” in the following strings, and then split on the first field after the “*”.

      NM1*QC*1*ABEYTA*SAM*E***MI*YIJ804039103

      NM1*QC*1*ADAM*MARK*S***MI*R51073202

      So, I should have YIJ804039103 or R51073202

      Please advise. Thanks.

    Viewing 4 reply threads
    • Author
      Replies
      • #82938
        Keith McLeod
        Participant

          Are you looking for something like:

          set j “NM1*QC*1*ABEYTA*SAM*E***MI*YIJ804039103”

          NM1*QC*1*ABEYTA*SAM*E***MI*YIJ804039103

          hcitcl>set k “NM1*QC*1*ADAM*MARK*S***MI*R51073202”

          NM1*QC*1*ADAM*MARK*S***MI*R51073202

          hcitcl>set j_value [lindex [split $j *] 9]

          YIJ804039103

          hcitcl>set k_value [lindex [split $k *] 9]

          R51073202

          Or something like

          hcitcl>regexp — {*MI*([^*s]*)$} $k {} k_match

          1

          hcitcl>echo $j_match

          YIJ804039103

          hcitcl>regexp — {*MI*([^*s]*)$} $k {} k_match

          1

          hcitcl>echo $k_match

          R51073202

        • #82939
          Femina Jaffer
          Participant

            Mark,

            Thank you so much for your quick response.

            I tried the same thing as you have suggested.  However, the problem I am having is that some times there will be  4 “*” and other times “3 “*” between the first name and “MI”.

            Eg. NM1*QC*1*ARAGON*ELOISA****MI*YIJ804040413

                NM1*QC*1*ARAGON*ELOISA***MI*YIJ804040413

            So, I am guessing I would need to split with the text “MI”, but not sure how to do that?

            Thanks,

            FJ

          • #82940
            Jim Kosloskey
            Participant

              Mypersonal opinion is chasing X12 with Tcl vs Xlate and variant is a waste of effort.

              In either case, you need to understand the entirety of the use of the X12 segment at the various levels and loops. So vendor documentation iis essential.

              It is also possible this particular provider of the X12 message is not following the standard although the X12 standard is quite vigorously enforced unlike HL/7.

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

            • #82941
              Charlie Bursell
              Participant

                Unless I am missing something here:

                Assume string to search is in variable named str

                set str {NM1*QC*1*ABEYTA*SAM*E***MI*YIJ804039103}

                # Just in case MI not there

                set wantStr “”

                set lst [split $str *]

                set loc [lsearch -exact $lst “MI”]

                if {$loc >=0} {set wantStr [lindex $lst [expr $loc + ]]}

                echo GOT: $wantStr

                YIJ804039103

              • #82942
                Femina Jaffer
                Participant

                  Thank you all for your responses, I really appreciated the timely solutions also.

                  Keith, I didn’t see the other option you had and that was the regex.  That certainly did the trick as well as Charlie’s solution.  I will treasure them and have added them to my documentation!  

                  Thanks again!

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