Parsing through variable length element

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Parsing through variable length element

  • Creator
    Topic
  • #47574
    Dan Loch
    Participant

      Hello TCL experts.

      I currently am getting the following in a lab result on our engine:

      CFC 999999 9999

      The 3 pieces are in a single element in the ORU message.

      I use:

      set xlateOutVals [ csubstr [lindex $xlateInVals 0] 0 3]

      set xlateOutVals [ csubstr [lindex $xlateInVals 0] 4 6]

      set xlateOutVals [ csubstr [lindex $xlateInVals 0] 11 4]

      To pull the elements out of the field.

      I am told that the second two pieces will now be sent in variable lengths.

      How do I pull these two pieces using TCL?

      Thanks,

      Dan Loch

    Viewing 2 reply threads
    • Author
      Replies
      • #56154
        Alice Kazin
        Participant

          If the elements are separated by a space, you could

          use “split” command to separate the elements.

        • #56155
          Terry Kellum
          Participant

            Try something like this:  

            (split is a wonderful command.  It will split {CFC 999999 9999} into

            {CFC} {999999} {9999} based on the space char.)

            set xlateOutVals

              { }] 0]]

              or

              set xlateOutVals

                { }] 1]]

                or

                set xlateOutVals

                  { }] 2]]

                  for each piece…

                  Assuming that you only have one item on the “input” side of your copy.

                  You can test that this is one item by having

                  set myitem [lindex $xlateInVals 0]

                  echo $myitem

                  if you get out CFC 999999 9999  then you know that this is a single item in the list.

                  Lists of lists of lists.  Keep it all square and it’s the best thing since sliced bread.  It WILL make your head hurt sometimes tho….

                1. #56156
                  Dan Loch
                  Participant

                    Thanks to those who replied – great help for those who are weak in TCL!!

                    Dan 😆

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