Testing for a meaningful space at the end of a field

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Testing for a meaningful space at the end of a field

  • Creator
    Topic
  • #54572
    Mike Strout
    Participant

      I have a quick, dumb little question today about a seemingly simple translate. On a barcode field, Epic passes a meaningful space at the end of the string. The downstream app strips this space, causing the barcode to break. The workaround from the vendor is to put a backslash at the end of the field if the last character is a space.

      Of course, Tcl sees the space and treats it as a list delimiter, so I do the following in the pre-proc box to capture the last character.

      set xlateOutVals [ string range [ join $xlateInVals ] end end ]

      I assign this to @lastChar, but can’t figure out how to test for a space in a xlate if statement. I have tried the following…

      @lastChar eq =            # yes, there is a space after the =

      @lastChar eq =” “

      @lastChar eq ={ }

      @lastChar eq =[ ]

      I finally got it to work by assigning a blank space to a variable named @space and then using…

      @lastChar eq @space

      Is there a better way to do this?

    Viewing 0 reply threads
    • Author
      Replies
      • #82053
        Robert Kersemakers
        Participant

          Hi Mike,

          Yes, it has been discussed a few times here that assigning a value to a variable and then comparing another variable with this one works; instead of comparing the variable against a value. So your solution is right.

          However… I don’t understand your problem. Tcl will not see the space and treat the space as a list delimiter; that is something you do yourself, or can avoid yourself.

          First rule of using tcl inside Cloverleaf: xlateInVals and xlateOutVals are lists, so always treat them that way!

          So if the barcode is “EAN12345 “, then

           COPY @barcodefield -> @otherfield

          with tcl code

          Code:

          lassign $xlateInvals code
          echo “this is the field that is coming in: ”
          set xlateOutVals [list $code]


          will show the full field and @otherfield will have the value “EAN12345 “

          So the piece of code to get the last character of a field is something like this:

          Code:

          lassign $xlateInVals code
          set last_char [string range $code end end]
          set xlateOutVals [list $code]


          or in short

          Code:

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

          If you want the code to add a backslash behind a field if the last character is a space:

          Code:

          lassign $xlateInVals code
          if {[string equal [string range $code end end] ” “]} {
           set code “${code}”
          }
          set xlateOutVals [list $code]

          Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

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