OBX-5 Help with Tilde “~” removal/replacement \.br\

Clovertech Forums Cloverleaf OBX-5 Help with Tilde “~” removal/replacement \.br\

Tagged: 

  • Creator
    Topic
  • #119281
    Sheila
    Participant

      I am trying to create one OBX-5 segment from the following:

      |test1~test2~test3 test4 test5~test6 test7|

      The outbound result would look like:

      |test1\.br\ test2\.br\ test3 test4 test5\.br\ test6 test7|

      So I am trying to read in the entire OBX-5 segment and replace “~” with “\.br\ “.  I have tried several things and am able to get “\.br\ ” but that is with an iterate and concat.  The issue is that the it would place a “\.br\ ” at the end as well.

      What would be nice is to be able to read in the entire OBX-5 as one string or list and then replace “~” with “\.br\ “.  However, I have not been able to get that to work.  Or to count each element and then iterate and concat them together via a loop which has not worked for me either.

      Note that each message will have different number of ~’s (tilde’s).

      Any help is very appreciated!

    Viewing 2 reply threads
    • Author
      Replies
      • #119282
        Jim Kosloskey
        Participant

          Once you have the OB field you can use Tcl string length command to get the length of the OB field and the string range command with first being 0 (zero) and last being end-5.  5 being the length of \.br\ to cut off the last \.br\.

          Assuming Cloverleaf release 6.1 or later:

          If the STRING Action substring Function would take data elements (like temp variables) as arguments this could be done without Tcl at all.

          STRING Action length Function would give you the length of the resultant OB field which you could put in a temp variable.

          Then you could calculate the needed end with a MATH Action (this would be then end argument of the substring Function). Let’s say @obx_lgth

          The if the substring Function honored the temp variable (which it does not) you could use 0 for the start and @obx_lgth for the end.

          Or you could use the STRING Action length Function to get the length, MATH Action to calculate the adjusted end, then some Tcl in a COPY to do a string range.

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

          • #119284
            Sheila
            Participant

              We are running 10.16.  The issue I am having is that it is only reading the first element.   So only test1 is read in. What I need to figure out is how to set a variable to the number of subsegments.  where that value can change from one message to another…

              Then I might be able to loop through to concat or append….

              |test1~test2~test3 test4 test5~test6 test7|

            • #119285
              Jim Kosloskey
              Participant

                I am not sure exactly what your issue is. But are you saying when doing the ITERATE on OBX-5 you are only getting the first value?

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

              • #119286
                Sheila
                Participant

                  Ok so the goal is to take OBX-5 (see example below):

                  |test1~test2~test3 test4 test5~test6 test7|

                  And make it look like this:

                  |test1\.br\ test2\.br\ test3 test4 test5\.br\ test6 test7|

                  My approach is 3 parts.

                  PART 1 – Add “\.br\ ” to the end of each segment even the last one.  I have completed this part successfully.  I was able to iterate through and copy IB OBX-5 to OB OBX-5.  and I used a Pre Proc Tcl:

                  set abc [lindex $xlateInVals 0 ]
                  set de “\\.br\\ ”
                  set out [concat $abc$de]
                  set xlateOutVals [ list $out ]

                  Result is:  |test1\.br\ ~test2\.br\ ~test3 test4 test5\.br\ ~test6 test7\.br\ |

                  PART 2 – Which is where I am stuck.   So the goal here is to remove the Tildes “~” from OBX-5.  So I am taking the results of PART 1 to produce the following:

                  |test1\.br\ test2\.br\ test3 test4 test5\.br\ test6 test7\.br\ |

                  I have tried to do a second iterate on that field to concat the elements but in all my efforts it seems to only read the first or last one.

                  PART 3 – Would be to remove the last “\.br\ ” from the field.  I plan to trim Right “\.br\ ” which I think will be fine if I could just get passed PART 2.

                   

                • #119287
                  Jim Kosloskey
                  Participant

                    OK I see.

                    Well for part 1 why not ITERATE over the Field OBX-5 (let’s say using %f1 as the variable) then inside the ITERATE CONCAT with the Source having OB OBX-5 (do not use the %f1 variable for the OB OBX-5 just leave that as zero thus pointing at the first OB repetition of OBX-5) and the current IB repetition of OBX-5 (use %f1 here) and place .\br\ in the CONCAT Action separator. The Destination would be the OB OBX-5 with no use of %f1 so that we only point to the first repetition of OB OBX-5.

                     

                    Now when Step 1 is done the OB OBX-5 should look like this:

                    test1\.br\ test2\.br\ test3 test4 test5\.br\ test6 test7\.br\

                    With an extra ./br/ at the end.

                    No need for your Step 2.

                    Step 3 Would be a COPY with the OB OBX-5 (results from Step 1) first and only repetition in the Source, Tcl to do the string range, and the Destination being the OB OBX-5 single an only repetition.

                    I don’t think the string trimright trims a ‘block’ (multiple characters as a set. I think it only trims one character.

                     

                    If you would like to discuss this, email me and we can chat off-line.

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

                • #119283
                  Charlie Bursell
                  Participant

                    Kind of squirrely, but this works for me.

                    In Xlate (assuming  0(0).OBX(0).#3)

                    COPY  @null -> @null    Tcl: set obx3 “”     # all variables are global in Xlate
                    PATHCOPY  @null ->  0(0).OBX(0).#3  # Clears field note no () at end
                    ITERATE field %f1 Basis 0(0).OBX(0).#3
                    Inside ITERATE
                    COPY  0(0).OBX(0).#3(%f1)  ->  @null  TCL: lappend obx3 [lindex $xlateInVals 0]
                    INTERATE Finished
                    COPY @null ->  0(0).OBX(0).#3     TCL: set xlateOutVals

                      ]

                       

                      Like I said, squirrely but works 🙂

                       

                       

                    1. #119288
                      Sheila
                      Participant

                        I was able to resolve the issue by doing a COPY of @null -> @obx5.  Then CONCAT “\.br\ ” to the OBX5 within an ITERATE.  This got rid of the ~’s (tildes) and placed “\.br\ ” to the end of each subsegment.

                        After the iterate, I COPY’d the variable to the OB OBX-5 and Tcl’d Trimmed Right:

                        lassign $xlateInVals obx
                        set obx [string trimright $obx “\\.br\ “]
                        set xlateOutVals [ list $obx ]

                        This was exactly what I needed.

                        Attachments:
                        You must be logged in to view attached files.
                        • #119290
                          Jim Kosloskey
                          Participant

                            I am glad you got it working – congrats!

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

                          • #119291
                            Jim Kosloskey
                            Participant

                              I think you could save using Tcl at all if you change your CONCAT Source to have:
                              @obx

                              …OBX#5(%f1)…

                              and place \\.br\\ (may not need the additional escapes) in the Separator entry of the CONCAT Action rather than in the Source.

                              Then I think the \.br\ value will be placed between the 2 source elements and not after the last repetition.

                              You could also save a temp variable by using the OB Field instead. This assumes the OB field is not pre-populated via prior Xlate Actions. If it is pre-populated then using a PATHCOPY @null to …OBX#5 (note no parenthesis, etc. following the OBX#5) should null the OB field in preparation for your solution.

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

                            • #119292
                              Jim Kosloskey
                              Participant

                                Never mind – starting the temp variable or the OB field with null then using the CONCAT like I described I think would then give you an extraneous leading \.br\. Sorry if I led you down a rabbit hole.

                                Well, you have it working the way you want.

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

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