Need to remove punctuation marks

Clovertech Forums Cloverleaf Need to remove punctuation marks

  • Creator
    Topic
  • #120945
    Abhishek
    Participant

      Hi All,

      Could you please help me with coding the fix for below issues.

       

      1.) CD EDM Note.pdf -> CD EDM Note

      For above value in OBR 4.1 & OBR 4.2, I want to remove .pdf

      2.) 20230710120318.418 -> 20230710120318418

      For above value in MSH-7, I want to remove .  character

      3.)20230710120318-418 -> 20230710120318418

      For above value in OBR-7, I want to remove – character

       

      I would really appreciate all the help I can get from the community on this. I tried regsub but something doesn’t seem to work right.

       

      Thanks,

      AJ

    Viewing 4 reply threads
    • Author
      Replies
      • #120946
        Jim Kosloskey
        Participant

          Are you trying to do this in an Xlate? If so, and you are on release 6.1 or later of Cloverleaf, look at the STRING Action Map Function.

          I have a treatise on the STRING Action which will help learn its various Functions.  Email me if you want that package.

          If Tcl, the string map there should do the trick. Here is a link to the doc:

          Tcl Built-In Commands – string manual page

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

        • #120947
          Robert Kersemakers
          Participant

            Lots of ways to do this. I assume you are doing this in an Xlate.
            Will make the code fairly readable; you can do this in 1 line though instead of 3.

            1.
            lassign $xlateInVals filename
            set name [file rootname $filename]
            set xlateOutVals

              2.
              lassign $xlateInVals field
              set field2 [string map {“.” “”} $field]
              set xlateOutVals

                3.
                lassign $xlateInVals field
                regsub -all “-” $field “” field
                set xlateOutVals

                   

                  Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

                1. #120952
                  Charlie Bursell
                  Participant

                    I would certainly lean toward the string map command in all cases.  It is is much more ergonomic and less confusing.  If I want to target something at a specific location in a string to modify I will use regsub.  But if I want to modify all instances of a string, string map is a better choice.  Quoting some of Roberts code:

                    For two of your cases:
                    lassign $xlateInVals field
                    set xlateOutVals [list  [string map {“.” “”} $field]]

                    For the other one:
                    lassign $xlateInVals field
                    set xlateOutVals [list  [string map {“.pdf” “”} $field]]

                    It is very important to use the list command when assigning to xlateOutVals in case of an imbedded space in the string.

                    While the file command would certainly work in the second case, I feel is would be more consistent to apply the same method in all cases.

                     

                     

                  • #120953
                    Robert Kersemakers
                    Participant

                      Somehow I botched my post. Firm believer/practitioner of always treating xlateInVals and xlateOutVals as lists. So the last line should be something like:

                      set xlateOutVals

                        Regarding removing the “.pdf” from the filename. It really depends what your intention is: do you want to remove all “.pdf” from the filename or do you want to remove the extension? If the filename is “test.pdftest.pdf” you will get different results.

                        Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

                      1. #120954
                        Robert Kersemakers
                        Participant

                          Wow! No idea why that one line of code gets truncated. I’m not going to try that a third time. 🙂

                          Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

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