Substring with Xlate

Homepage Clovertech Forums Cloverleaf Substring with Xlate

  • Creator
    Topic
  • #115422
    Rich
    Participant

    This is an awesome forum with very responsive folks, and I truly appreciate you all!!!

    I need to strip the last three characters off of an accession number.  10501496SMR  The SMR needs to be removed from the field.  Is there a way to do a substring replace with an xlate?

    Thanks,

    Rich

Viewing 4 reply threads
  • Author
    Replies
    • #115423
      Paul Bishop
      Participant

      Yes, but the way you do it can depend on how the data will be.  Will it always be the same length?  Will the characters always be “SMR”?  Will the characters you want to remove always be three characters?

      If it is always three characters from the end you want to remove, the quick way is to use the string range command.  In the pre-proc portion of the xlate copy:

      lassign $xlateInVals in_data

      set out_data [string range $in_data 0 end-3]

      set xlateOutVals

         

        If it isn’t always three characters, it gets a little more tricky.

         

        • This reply was modified 4 years, 8 months ago by Paul Bishop.

        Paul Bishop
        Carle Foundation Hospital
        Urbana, IL

        • #115453
          Rich
          Participant

          Thank you for the great response!  With the pre-proc, how do I get the OBR.18 value in, and then replace it back in OBR.18 after it is processed?

        • #115464
          Jim Kosloskey
          Participant

          Set the Source in the Xlate to point to the IB OBR-18 and the Destination to point to the OB OBR-18. Use a COPY Action. XlateOutVals is a list of the specified Destination address(es).

          Seriously though if you have the STRING Action – use it.

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

      1. #115425
        James Nelson
        Participant

        You could use a TCL fragment.
        <pre>set xlateOutVals [string range [lindex $xlateInVals 0] 0 end-3]

        </pre>

      2. #115428
        James Cobane
        Participant

        <pre>One thing to keep in mind is to always treat xlateInVals and xlateOutVals as ‘lists’.  So, when setting xlateOutVals, treat it as a list:

        set xlateOutVals [ list $out_data ]

        or

        set xlateOutVals [ list [string range [lindex $xlateInVals 0] 0 end-3] ]

        using the above examples.

        Jim Cobane
        Henry Ford Health System</pre>

        • This reply was modified 4 years, 8 months ago by James Cobane.
      3. #115429
        Anonymous
        Inactive

        One way of many:

        [ string range {10501496SMR} 0 [ expr [ string length {10501496SMR} ] – 4 ] ]

      4. #115431
        Keith McLeod
        Participant

        Or the latest favorite, and yes it depends on what you are trying to accomplish, use the string command with the following function:

        xlateStrSubstring 0 end-3

        • #115445
          Jim Kosloskey
          Participant

          This is what I recommend if your release of CL has the STRING Action.

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

    Viewing 4 reply threads
    • You must be logged in to reply to this topic.

    Forum Statistics

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