Question

  • Creator
    Topic
  • #55740
    mike brown
    Participant

      I have a message coming in HL7 with xxx-ABCD-xdcs, I want the first 2 characters after the HYPHEN always, so I use this below.

      in tcl : set xlateInVals xxx-ABCD-xdcs and I run

      set xlateOutVals

        4 5]]

        returns

        AB — this is correct

        but what if it comes in like this…

        set xlateInVals xxxx-ABCD-xdcs ,

        -A not correct .. then the above does not work.

        I want the first 2 characters after the first HYPHEN no matter how long the characters are in front of the HYPHEN.

        any ideas…?

      Viewing 4 reply threads
      • Author
        Replies
        • #86358
          Jim Kosloskey
          Participant

            Mike,

            If you are on 6.0 or later you can utilize 2 STRING Actions.

            The first STRING Action would use the split function specifying ‘-‘ as the split character and 2 outbound fields (temp variables for ex @tmp1 and @tmp2).

            The second STRING Action would use the substr function against the @tmp2 created above specifying 0 and 1.

            Or I am sure there is some sort of regsub expression you can use if you just want to use Tcl. But I am not the person to advise on regsub.

            Edited to add comments regarding Tcl split and range…

            You could apply the Tcl split command to split the string into a list. The second element of that list is then the field you want to apply your range to.

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

          • #86359
            Levy Lazarre
            Participant

              Hi Mike,

              If you don’t want to use a regular expression, an easy way is to split the string on HYPHEN, take the second component of the resulting list, then take the first two characters of the result:

              Code:



              string range [lindex [split $xlateInVals -] 1] 0 1

              With a regular expression:

              Code:



              set exp “.*?-(..)”

              regexp — $exp $xlateInVals {} $first2chars

              $first2chars is the value you are looking for

              I hope this helps

            • #86360
              mike brown
              Participant

                thank you I got it to work…. the replies helped me get it to work, I should say. lol

              • #86361
                Robert Kersemakers
                Participant

                  😈 Always treat xlateInVals and xlateOutVals as a list:

                  Code:

                  set xlateOutVals [list [string range [lindex [split [lindex $xlateInVals 0] -] 1] 0 1]]

                  Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

                • #86362
                  mike brown
                  Participant

                    thank you all it works beautifully, exactly what I was looking for.

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