9 Replies Latest reply on Mar 18, 2013 4:51 AM by apw

    Search operations on text strings containing '#', '""' and '!'

    apw

      Title

      Search operations on text strings containing '#', '""' and '!'

      Post

           I notice, that search operations on text strings containing these signs/tokens/characters run into problems.

           I think I understand the reason: these signs have been assigned a special role as FMP search operators.

           That's bad luck, and I can't ask the FMP programmers to change these signs.

           My question is: Is there any way to neutralize the presence of these signs in the search operation, so that  it produces the expected results?

        • 1. Re: Search operations on text strings containing '#', '""' and '!'
          philmodjunk

               Put the search criteria in quotes. This can be done in both manual and scripted finds.

               "#" finds records that contain the actual # character instead of "any numeric digit".

          • 2. Re: Search operations on text strings containing '#', '""' and '!'
            apw

                 Thanks for your useful suggestion, but what about quotation marks?

            • 3. Re: Search operations on text strings containing '#', '""' and '!'
              apw

                   More precisely, I have two problems.

                   First putting the search criteria in quotes.

              Substitute ( text ; "!" ; "!\"" )  results in  #", only one quotation mark in stead of two

                   Secondly, I search for the # and ! sings with Filter ( text; "!" ) = "!" , but that doesn't work with quotation marks.

                   I cannot find them, let alone put them between quotation marks.

              • 4. Re: Search operations on text strings containing '#', '""' and '!'
                philmodjunk

                     To enclose text in quotations you can use

                     "\"#\""

                     Quote ( "#" )

                     """#"""

                     

                          Secondly, I search for the # and ! sings with Filter ( text; "!" ) = "!" , but that doesn't work with quotation marks.

                     I don't understand what you are tyring to do with that expression in terms of searching for text. A scripted find for # in a field might look like this:

                     Enter Find Mode[] ---> clear the pause check box
                     Set FIeld [YourTable::YourTextField ; "*" & Quote ("#" ) & "*" ]
                     Set Error Capture [on]
                     Perform FInd []

                     No filter used. No Subsitute used.

                     For more examples of scripted finds, see this thread: Scripted Find Examples

                • 5. Re: Search operations on text strings containing '#', '""' and '!'
                  apw

                       Thanks for your solution.

                       What I try to do is to perform a search operation with 'text', but as long as the quotation marks are not neutralized the search is not performed correctly.

                       Finally I came - with your help -to the following solutions:

                        

                       first problem                   Substitute ( ${text ; "#" ; Quote ( "#" ) )

                        

                       second problem            Filter ( ${text; "\"" ) = "\"" or Filter ( ${text; "\"" ) = "\"\""

                                                            Substitute ( ${text ; "\"" ; Quote ( "\"" ) )

                  • 6. Re: Search operations on text strings containing '#', '""' and '!'
                    philmodjunk

                         In what context are you using those expressions?

                         In my examples, there are no "quotation marks to neutralize".

                         Your "first problem" takes every instance of # and replaces it with "#". This is not necessary to do as search criteria for a find.

                         Your "second problem" returns True (the number 1) if text contains only a single quotation mark in the first line where you have the same exact expression  listed twice separated by "OR".  (You bascically have text = "\"" Or text = "\"" ). The second line, which shows no operator linking it to the first line, turns " into """ ---which really makes no sense in this context.

                         Also, ${text will trip a syntax error as written. Presumably, you meant ${text}, but the ${ } notation is only needed if your field or variable name contains characters that are normally used as operators in a calculation such as +, =, etc.

                    • 7. Re: Search operations on text strings containing '#', '""' and '!'
                      apw

                           I have to determine whether an artist or an album is already present in my collection.

                           [I have four (songs, albums, artists, songwriters) FMP databases which I feed from the xml iTunes file.)

                           So I search for the artist or album in the related file, which works fine as long as no FMP-specific search operators like "!, '#' and '"' are included in the search text; in that case I have to 'neutralize' them by placing them between quotation marks, e.g. the text <Johnny "Guitar" Watson> doesn't work, but <Johnny \"Guitar\" Watson> does. The same goes for the'#' sign; I have to place it between quotation marks, otherwise the search operation fails.

                           The search is of the type Enter Find Mode, Set Field, Perform Find.

                           $(text indeed stands for an simplified variable; in this form it doesn't work, I removed the dutch varable name.

                           As regards my use of the Filter function, I agree it looks rather primitive, but it works; I use it to identify a text variable with one or two quotation marks or other signs; in this case Filter($(text;"\"") = "\"\"" would suffice. In fact I am not filtering anything, just looking for something

                           I have in the meantime  replaced this line with < If PatternCount(text; "\"") >1, which is simpler and more elegant.

                           I hope I answered your questions and thanks for your interest.

                      • 8. Re: Search operations on text strings containing '#', '""' and '!'
                        philmodjunk

                             Yes, PatternCount works where your original expressions did not.

                             Note, however that in most cases, you can simply put the entire text in quotes.

                             If the user enters Johnny "Guitar" Watson into a global text field or your script copies that into a variable, you should be able to use:

                             Set FIeld [YourTable::TextField ; Quote ( YourTable::GlobalFIeld ) ] // or Quote ( $Variable )

                             which will enter the exact search criteria:

                             "Johnny "Guitar" Watson"

                             Since this text is not evaluated as a text expression, there should be no need to insert escaped quotes before and after "guitar" and no need to uses tests to detect the presence of any search operator characters.

                        • 9. Re: Search operations on text strings containing '#', '""' and '!'
                          apw

                               Sorry for my late answer, I was doing something else.

                               I tend to agree with you: I invented a complicated solution to an apparently non-existing problem.

                               Everything now works fine with your suggestions applied..

                               Thanks again.