13 Replies Latest reply on Jul 14, 2017 12:38 PM by AdamReed_1

    escaping apostrophe in variable

    AdamReed_1

      Hello,

       

      I have a script which saves records as a number of pdfs to folders which match the filenames of the pdfs. The filenames are determined by a text field (variable $name, for example).  For example, the record in which the name field is "Smith" will save as a pdf named "Smith.pdf" to a folder called "Smith."  That is no problem.  When text of the name field contains a special character such as an apostrophe, however, such as "O'Brien" I get an error as I haven't escaped the apostrophe correctly.  I've tried to research this, and thus far I have tried:

       

      Set Variable ($name; Value: (person::name)

      Set Variable ($name; Value:GetAsText (person::name)

      Set Variable ($name; Value:Substitute (person::name ; "'" ; "\'")

      Set Variable ($name; Value:Substitute (person::name ; Char(39) ; Char(92) & Char(39) )

       

      However none of these seem to do the trick.

       

      Any thoughts?

       

      Thanks,

      Adam

        • 1. Re: escaping apostrophe in variable
          jonmyrah

          Try:

           

          Set Variable ( $name ; Value: Filter ( person::name ; "abcdefghijklmnopqrstuvwxyv" ) )

          • 2. Re: escaping apostrophe in variable
            beverly

            That would "toss" the uppercase characters.

            Filter ( person::name ; "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ) // add other allowed charcters.

            I tend to remove spaces, but I might Subsitute them with underscore ("_") when saving the name to a file (such as a PDF).

            Beverly

            2 of 2 people found this helpful
            • 3. Re: escaping apostrophe in variable
              beverly

              an alternative is to:

              Filter ( Lower(person::name) ; "abcdefghijklmnopqrstuvwxyz" )

              That already converts to all lower (or Upper as desired) and then filters out anything not matching.

               

              I try to also avoid accented characters in filenames, so you may have substitutes for those, if needed.

              Beverly

              • 4. Re: escaping apostrophe in variable
                philmodjunk

                I like beverly's solution here, but as a side note, quotes, both single and double can be "smart" quotes that curl left or right and they have different character codes so if you substitute to remove the "straight" version and not those that "curl", your substitute won't find them to remove.

                2 of 2 people found this helpful
                • 5. Re: escaping apostrophe in variable
                  AdamReed_1

                  Thank you Beverly (and all) -- yes, the first answer did toss the upper characters and spaces.  That was a confusing surprise until I figured out what was going on.

                   

                  I think I may not have been clear -- I do understand it isn't recommended, but I would like to preserve the apostrophe's (and accent marks) in the filenames and the folder names, so that O'Brien does come across as O'Brien.  So ideally we'd have a solution in which special characters don't cause an error (which they're currently doing) in the script.

                  • 6. Re: escaping apostrophe in variable
                    philmodjunk

                    I don't think that you can. It's not a matter of escaping the character, but that the character is not permitted in a file field name just as the / is not allowed.

                    • 7. Re: escaping apostrophe in variable
                      brianb

                      I think I may have found a workaround.   The "Save As Filename" doesnt seem to like the " ' ", but if you create a var then insert that var into another var  you can achieve an output pdf filename that contains " ' "

                       

                      I was able to save a field value that contained " ' " as a  dynamic labeled pdf

                       

                      **** edit    i changed the references and didnt realize it added " "  as seen in the screenshot.  idea is there  syntax is off :-)

                       

                       

                       

                      Capture.PNG

                      • 8. Re: escaping apostrophe in variable
                        beverly

                        I understand that you want to keep the file name to match exactly. The issue may not be with creating anything you desire in the variable. The biggest problem may be the file system for the OS (Mac/Win) to which that document is being saved. It may still burp at you and mangle your carefully created file name. Or it may "save" ok, but not be attachable to an email, for example. 

                         

                        My advice is merely to guide you to a better way for naming files that is decades proven efficient.

                        Beverly

                         

                        Sent from miPhone

                        • 9. Re: escaping apostrophe in variable
                          brianb

                          agree 100% ^^

                           

                          There is a reason why filemaker prohibits certain characters and then validates the function prior to execution.  my guess is that it is ,in  regards to the export filename names,  due to reserved/prohibited characters/words relative to the Operating systems' functionality.

                           

                          the  work around is a solution, but comes with unforeseen risks  due to bypassing (assuming the validation is a single level)  Conventions  are always the safer. To mitigate risk you could  possibly include a custom function to exclude a

                          list of prohibited characters/words as part of your variable calculation. Those prohibited characters and custom functions can be found via google search

                          • 10. Re: escaping apostrophe in variable
                            user19752

                            Apostrophe (single quotation) is not special character on Windows.

                            1 of 2 people found this helpful
                            • 11. Re: escaping apostrophe in variable
                              brianb

                              thank you for identifying a specific point on a generalized topic.....however not everyone uses windows.  In unix/linux based environment an apostrophe is a reserved character in a filename because it can interpreted by the shell in different ways.  Same applies to leading " -" 's as well as other control characters.

                               

                              List of filename prohibited characters used in a funix/linux based environment

                              & ; | * ? ' " ' [ ] ( ) $ < > { } # / \ ! ~

                              1 of 1 people found this helpful
                              • 12. Re: escaping apostrophe in variable
                                brianb

                                Somewhat related..

                                 

                                quick and dirty list of characters that should be avoided in filenames:

                                Characters to Avoid in Directories and Filenames | University Marketing and Communications | Michigan Technologi…

                                 

                                link to custom function to strip string of non-printable control characters (ASCII  1-32)

                                FileMaker Custom Function:_FilterLowerASCII (Text)

                                1 of 1 people found this helpful
                                • 13. Re: escaping apostrophe in variable
                                  AdamReed_1

                                  Thank you all very much -- using that workaround I've got these pdfs saving as intended.

                                   

                                  Normally I'm quite mindful of not using special characters in filenames and paths (and do understand the problems associated), but in this particular case I'd at least like to be able to have this as an option.