XLATE TCL Question

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf XLATE TCL Question

  • Creator
    Topic
  • #53372
    Jon Melin
    Participant

      Hi. I have a question regarding some TCL code used in my XLATE. I am trying to grab the first letter of a field coming in to filter by that letter. In this case the first letter is always ‘H’ – If it has an H I want to keep it, if it doesn’t I want to get rid of it. I already have everything setup in the IF statement to take care of this except I am having a hard time grabbing the H off the front to verify it is an H.

      What I am doing:

      1(0).0(0).0(0).PID(0).#3(0).[0]

    Viewing 1 reply thread
    • Author
      Replies
      • #77460
        Robert Kersemakers
        Participant

          Hi Jon,

          You are having problems with xlateInVals and xlateOutVals. xlateInVals is a list of values coming into the tcl-portion; xlateOutVals is a list of values leaving the tcl.

          So you would need something like this:

          Code:

          # Assign xlateInVals to variable
          lassign $xlateInVals pid3
          # Search for the first ‘H’ in the string
          set first_h [string first “H” $pid3]
          # Return this value, as a list!!
          set xlateOutVals [list $first-h]

          This should return -1 if there is no ‘H’ in PID-3; 0 if ‘H’ is the first character or a value > 0 to indicate where the first ‘H’ is found in PID-3.

          Not sure though what you want to do with the outcome of this tcl-portion; to what field or variable is this going?

          Do you want to keep the complete message only if PID-3 starts with an H? I wouldn’t do this in the Xlate, better to do it with a Pre-Xlate tcl-script.

          Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

        • #77461
          Jim Kosloskey
          Participant

            Jon,

            The string first will find the first occurrence of the H in the string which is not necessarily the first actual byte of the string being interrogated.

            You might want to combine the string first with a string index command to asure you are only checking the first character.

            Something like this:

            string first “H” [string index [lindex $xlateInVals 0] 0]

            I have not actually tested the above code so it might need some tweaking.

            You could also do that in 3 lines of code if that makes maintenance and/or troub leshooting easier for you.

            email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 60 years IT – old fart.

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