Need some help with split

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Need some help with split

  • Creator
    Topic
  • #53560
    Dan Drury
    Participant

      I am trying to split up a name field that is delimited by a comma.

      The field may look like:

      De La Roberto, Garcia

      I have added a tcl preproc of

      set xlateOutVals  [split $xlateInVals ‘,’ ]

      and am getting close…

      I get {De La Roberto  as the first element but I can’t get rid of the {

      I get ” Garcia}” as the second element and can’t trim the white space or get rid of the trailing }

      Any advice or guidance would be greatly appreciated.

    Viewing 7 reply threads
    • Author
      Replies
      • #78116

        This is how it’s done:

        set xlateOutVals  

          ,]]

          -- Max Drown (Infor)

        1. #78117
          Derrick Ray
          Participant

            Just always remember that xlateInVals and xlateOutVals are lists and always need to be treated as such.

          • #78118
            Russ Ross
            Participant

              In case your question is just the tip of a much bigger iceburg on how to reformat malformed non-HL7 compliant names,  here is a clovertech post where I show the proc I wrote called xlt_parse_name.tcl to help address most of our various malformed names.

              <a href="https://usspvlclovertch2.infor.com/viewtopic.php?t=4845&#8243; class=”bbcode_url”>https://usspvlclovertch2.infor.com/viewtopic.php?t=4845

              Russ Ross
              RussRoss318@gmail.com

            • #78119
              Dan Drury
              Participant

                Almost there:  

                If I have the source of:

                “De La Smith, Tommy”

                and I use a preproc tcl of

                set xlateOutVals  [string trim [lindex $xlateInVals 0] ]

                To destination @name1 and @name2 I get

                @name1 =De La Smith

                @name2 = Tommy  (with the leading space)

                I can then apply a preproc tcl of:

                set xlateOutVals  [string trimleft [lindex $xlateInVals 0]]

                With source of @name2 to get rid of the leading space

                My final issue is if @name2 =” Tommy III” I lose the III

                Is there a way to concatenate all elements of a list into a single string, or, specify something other than a blank space as the delimiter of a list?

              • #78120

                The xlateInVals and xlateOutVals are used by Cloverleaf as LIST variable not as strings. This is very important to understand. As such, they must be treated as list variables by your tcl fragments or xlt procs. These variable contain a list of elements starting with element 0. The proper and safe way to retrieve data from these list variables is with lindex (or other appropriate list commands). And the proper way to place data into these list variables is with the list command (or other appropriate list commands). Each element in these lists correspond directly to the list of values specified in the xlate source or destination fields respectively.

                If you treat these list variables as strings, the you are at risk of losing data when white space is introduced to the data sush as you would see in a mailing address (ex. 101 State St).

                List values in tcl are basically strings seperated by spaces. If a value needs to contain a space then it needs to be wrapped in quotes or braces.

                Examples:

                set xlateInVals

                  lappend xlateInVals “abc”

                  lappend xlateInVals “xyz”

                  set var1 [lindex $xlateInVals 0]

                  set var2 [lindex $xlateInVals 0]

                  set var1 [string trim [lindex $xlateInVals 0]]

                  set var1 [string trim [split [lindex $xlateInVals 0] ,]]

                  set xlateOutVals

                  set xlateOutVals

                  set xlateOutVals

                    ,]]]

                  -- Max Drown (Infor)

                • #78121
                  Russ Ross
                  Participant

                    I see you’re starting to discover the rest of the iceburg.

                    To give you a peak of other cases the method/proc I posted covers, here are comments from the proc’s header, which covers the III case you are now asking about.

                    Code:

                    # Example of name variations tested for desired_name = “last^first^middle” :
                    #
                    #        name_in               name_out
                    #        ——-               ——–
                    #    01) Ross^Russ^K           Ross^Russ^K
                    #    02) Ross^Russ             Ross^Russ
                    #    03) Ross^Russ^            Ross^Russ
                    #    04) Ross^Russ^,           Ross^Russ
                    #    05) Ross^Russ K           Ross^Russ^K
                    #    06) ^Russ^                ^Russ
                    #    07) ^Russ                 ^Russ
                    #    08) Ross^                 Ross
                    #    09) Ross, Russ K          Ross^Russ^K
                    #    10) Ross ,Russ K          Ross^Russ^K
                    #    11) Ross, Russ            Ross^Russ
                    #    12) Ross, Russ,           Ross^Russ
                    #    13) Ross, Russ,^          Ross^Russ
                    #    14) Ross ,Russ            Ross^Russ
                    #    15) Ross ,Russ,           Ross^Russ
                    #    16) Ross ,Russ,^          Ross^Russ
                    #    17) Ross, Russ Jr. K      Ross^Russ Jr^K
                    #    18) Ross ,Russ Jr. K      Ross^Russ Jr^K
                    #    19) Ross, Russ III, K     Ross^Russ III^K
                    #    20) Ross ,Russ III ,K     Ross^Russ III^K
                    #    21) De La Cruz, David     De La Cruz^David
                    #    22) De La Cruz ,David     De La Cruz^David
                    #    23) Ross                  Ross
                    #    24) De La Cruz            De La Cruz
                    #    25) Ross^ ^               Ross
                    #    26) Ross^^K               Ross^^K
                    #    27) Russ K                Russ^^K          (this case works as programmed)
                    #    28) Ross^^                Ross
                    #    29) Ross^R^K              Ross^R^K
                    #    30) Ross^R                Ross^R
                    #    31) Ross^R^               Ross^R

                    Russ Ross
                    RussRoss318@gmail.com

                  • #78122

                    Ex. De La Smith, Tommy III

                    Code:

                    set name1 [string trim [split [lindex $xlateInVals 0] ,]]
                    set name2 [string trim [split [lindex $xlateInVals 1] ,]]
                    set xlateOutVals [list $name1 $name2]

                    -- Max Drown (Infor)

                  • #78123
                    Dan Drury
                    Participant

                      Russ,

                      Thank you for your guidance.  

                      Having this be the tip of the iceberg is an understatement.  Parsing data from systems that did not normalize name data is quite challenging.  I am going to put your script in place as a stop gap but need to build in the ability to parse out the suffix.

                      Your code comments with pattern matching is genius!  Thank  You.

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