1 2 Previous Next 17 Replies Latest reply on Sep 25, 2014 2:21 PM by steve_ssh

    Need to find the full string based on searching for part of it.

    madmike6537

      Hello all,

       

      I am trying to find a custom, or built in, function that will allow me to search for a string value, and will return all text including my search string plus any text after it up to a point I indicate.

       

      For example:

       

      If the text I am searching in is:

       

      thebigdog~

       

      I want to be able to search for "the" and provide the end value of "~" and it will return "thebigdog".

       

      Here is my ultimate goal of using this, maybe there is an easier way all together:

       

      I have a return seperated value list. I am trying to build a custom function that will delete a value when I input a search string. But, the search value wont ever know the full string of what is being deleted - it only knows part of it. Thats why it needs to be able to search until it hits a return, ideally.

       

      So I might have these values:

       

      oneValue

      twoValue

      threeValue

       

      I need to be able to pass "two" and have it delete the full string "twoValue"

       

      Hope that makes sense!! I have been working on this for several hours. Here is what I have so far (using a custom function called "PositionValue" which I renamed GetItemRank: which returns the line that the string is on, but I have to get the full string value, which I dont have

       

       

      Let([

       

       

      rank = GetItemRank ( PropertyList ; Name ; 1 ; 1 );

      string = MiddleValues(PropertyList; rank; 1)

      ];

       

       

      Substitute(PropertyList; string; "")

       

       

      )

        • 1. Re: Need to find the full string based on searching for part of it.
          steve_ssh

          Hello Mike,

           

          I'm sure you'll soon get some top-notch suggestions on this.  In the meantime, I'd like to ask you a couple of questions to really hone in on the desired behavior.

           

          Given your example of having the following:

           

             oneValue

             twoValue

             threeValue

           

           

          Questions for you:

           

          1) Do you expect an input such as "eva" to be able to find and delete a value such as "oneValue" or "threeValue", or is there no requirement for doing a search where the search string starts in the middle of the target value?

           

          2) Given the input of "t", what is the desired outcome:

           

                - Delete just one of the matched values, e.g. "twoValue" ?

           

                - Delete all of the matched values, i.e. "twoValue" and "threeValue"?

           

                - Something else?

           

           

          HTH & best,

           

          -steve

           

           

           

          Message was edited by: steve_ssh

           

          Corrected mistake in question 1:  Had typed "twoValue" when I should have typed "threeValue".

          • 2. Re: Need to find the full string based on searching for part of it.
            steve_ssh

            Hello Again Mike,

             

            It turns out that I had a parsing function lying around that does stuff very close to your large goal of modifying a list of values.

             

            I will attach a file that illustrates its use.

             

            I've little doubt that someone will think of something more elegant/efficient, but perhaps this will be of some use in the meantime.

             

            Details from the CF comments are below.

             

            HTH & Best,

             

              -steve

             

             

             

             

             

             

             

            Function Name:

             

              ParseMatchingLines

             

             

             

            Synopsis:

             

              Accepts input which is a set of lines of text.

             

              Returns a modified subset of lines, omitting either matched or unmatched values, depending on use.

             

              Matches are case-insensitive, and performed against each line by comparing the line to a supplied search string.

             

              Matches can be optionally constrained to matching only if the match string appears at the start of the target line.

             

              Leading match strings can be optionally stripped from returned lines.  I have found this to be helpful in building some crude HTML parsing routines.

             

              Empty lines are never included in function output.

             

             

             

             

            Function Signature:

             

              ParseMatchingLines( LineData; MatchString; MatchOnlyFromStart; StripLeadingMatchStrings; OmitMatches )

             

             

             

             

            Explanation of Parameters:


              LineData:  A string of return-delimited/line-feed-delimited text to search through.

             

              MatchString:  Case-Insensitive string to search for in each line.

             

              MatchOnlyFromStart:  Set to True to find only lines which *begin with* MatchString.

             

              StripLeadingMatchStrings:  Set to True to strip the leading MatchString from returned lines.  Otherwise set to False.

             

              OmitMatches:  Set to True to return only lines which do *not* match.  Set to False to return only lines which *do* match.

            1 of 1 people found this helpful
            • 3. Re: Need to find the full string based on searching for part of it.
              madmike6537

              Hi Steve,

               

              Thanks for both your responses - I just made it back to the thread.

               

              I will check into your CF file there and see if that will work. I need to look a little closer at it tonight, but from the description it sounds like it would do what I would want!

               

              As for your first reply and the questions - I guess if I was making a more "reusable" custom function I could better answer that. Right now, its being designed for a specific purpose, so it doesnt have to be all that flexible. In my case, I already know that the first digits of the string will always be a primary key of a few numbers, and the script will always know the primary key it is searching for - it just doesnt know what comes after that.

               

              So a standard string of the text would be something like this (there would be a bunch of these seperated by carriage returns):

               

              1234=444|fan


              Which is

               

              RoomPrimaryKey=equipmentID#|typeOfEquipment

               

              I know the primary key, but I need to find the equipment ID and type of equipment. And I also need to be able to delete the whole thing which is what I am trying to sort out right now.

               

              Basically, I need a list of all the related equipment records, that are related to my one "room" table record at all times. I first thought I might do a summary field showing related equipment with counts, but I need to know how many of each type of equipment as well, and there are several different kinds. I didnt want to create 10 different summary fields to add up how many of each type of equipment is in the room, so I thought I would just have one field, which holds a list of all the equipment.

               

              That is what I am trying to achieve..   Hopefully that didnt make it more confusing.

              • 4. Re: Need to find the full string based on searching for part of it.
                erolst

                madmike6537 wrote:

                Basically, I need a list of all the related equipment records, that are related to my one "room" table record at all times. I first thought I might do a summary field showing related equipment with counts, but I need to know how many of each type of equipment as well, and there are several different kinds. I didnt want to create 10 different summary fields to add up how many of each type of equipment is in the room,

                 

                That is not how summaries work; you have one summary field that does the aggregating for each of many groups.

                 

                You can do all this with the usual tools, and even some unusual ones; but a recursive CF isn't really necessary.

                 

                (And you can see why it is usually better to describe what you want to achieve, and not what may be wrong with some particular method.)

                 

                See if the attached file helps.

                • 5. Re: Need to find the full string based on searching for part of it.
                  madmike6537

                  Thanks for the reply erolst,

                   

                  Sorry for not being more clear at the start, I am just trying to prevent asking someone to do all the work for me and be more specific in my requests, but I can see there may be another way to acheive what I am looking for.

                   

                  Thank you for the demo file I will take a look.

                  • 6. Re: Need to find the full string based on searching for part of it.
                    steve_ssh

                    Hi Mike,

                     

                    Thank you for posting more info.  Though I don't understand the requirements 100%, you made things more clear by posting what you did.

                     

                    I seems as though you are going down the path of creating db table-like functionality with a CF because using actual db table(s) and schema did not seem workable.

                     

                     

                    If this is the case:

                     

                    I'd suggest that you start a post describing your system's requirements, and see if anyone suggests a good design that does not require you to implement your own table-like functionality via a delimited list.

                     

                    Someone may suggest something that suddenly makes it all seem much more workable in an elegant fashion that uses standard FM table/relationship functionality.

                     

                    If you can go the route of using FM's built in db abilities, rather than implementing your own, your project will probably benefit in the long term by having greater scalability and maintainability.

                     

                     

                     

                    Having said the above:

                     

                    I'd like to applaud you for being resourceful and figuring out your current scheme.  I think that's great, and a great way to learn.

                     

                    And, it still may be among the most viable solutions, but I think it's definitely worth soliciting some other suggestions before deciding whether or not that is the case.

                     

                     

                     

                    HTH & very best,

                     

                    -steve

                     

                     

                     

                    Message was edited by: steve_ssh

                     

                       Case in point: erolst's post -- I did not see it when I posted this message.

                    • 7. Re: Need to find the full string based on searching for part of it.
                      madmike6537

                      Based on your reply and Erolst, there is probably a better way to do this - though I should say that your CF you posted actually works perfectly for what I had invisioned!

                       

                      So here is my scenario - again I feel almost like cheating for just posting this and asking for step by step instructions but if you are willing to help then I cant pass that up

                       

                      I have a webviewer with a HTML Canvas element which allows me to show where equipment is located in a room by drawing little boxes. Using Javascript, I create the little box for every peice of equipment that is located in my Equipment table in filemaker. But, I need to show different boxes for different peices of equipment, and I also need to display the equipment ID (not the primary key but the ID) on my icon.

                       

                      My filemaker table set up is ROOM ----<  Equipment

                       

                      Without a filemaker script, or without leaving my layout page, I need to have a list of all the equipment that is in my related equipment table, and I need to know what type of equipment it is, and the ID number for the equipment (these are both fields in the equipment table). That way, in my javascript code in filemaker I can loop through the data, and add a box for every peice of equipment (with a different color, or maybe graphic for each type of equipment), and then attach the ID number onto the box that is drawn.

                       

                      Thats it!   Here is a picture of my work in progress webviewer if that helps visualize it:

                       

                      Capture.JPG

                       

                      Message was edited by: madmike6537

                      • 8. Re: Need to find the full string based on searching for part of it.
                        erolst

                        madmike6537 wrote:

                         

                        a list of all the equipment that is in my related equipment table, and I need to know what type of equipment it is, and the ID number for the equipment (these are both fields in the equipment table).

                        Sorry, no step-by-step …

                         

                        As you can see from my sample file, you (probably) should have a structure like

                         

                        Rooms R --< RoomEquipment RE >-- Equipment E

                         

                        Now do you need a list of related entries from RE (i.e. every single piece of equipment in a room), or from E (i.e. every type of equipment used in that room)? Or both?

                         

                        Either way, you could read that as a list (or several lists) via the relationship chain, then pass that (them) as proper array(s) to your JavaScript code (simple substitution, IIRC) and let it do the looping.

                        • 9. Re: Need to find the full string based on searching for part of it.
                          madmike6537

                          I would need both -

                           

                          I need to know every peice of equipment in the room, its ID number, and its type.

                           

                          I guess the part I am missing is how I read that as a list. Is that a summary field similar to your demo file then?

                          • 10. Re: Need to find the full string based on searching for part of it.
                            erolst

                            Well, in your Web Viewer calculation, declare some array variables like

                             

                            Let ( [

                              listIDs = Substitute ( List ( RoomEquipment::id_equipment ) ; ¶ ; "," ) ;

                              listNames = "'" & Substitute ( List ( RoomEquipment::cEquipmentName ) ; ¶ ; "','" ) & "'" ;

                              listTypes = "'" & Substitute ( List ( RoomEquipment::cType ) ; ¶ ; "','" ) & "'" ;

                              listCoorX = Substitute ( List ( RoomEquipment::coordX ) ; ¶ ; "," ) ;

                              listCoorY = Substitute ( List ( RoomEquipment::coordY ) ; ¶ ; "," )

                              ] ;

                              "YourHTML&JS"

                            )

                             

                            and insert them into the JS code.

                             

                            And I still think you should have a three-table structure …

                            • 11. Re: Need to find the full string based on searching for part of it.
                              steve_ssh

                              Hi Mike and erolst,

                               

                              1)  I agree with erolst about the three-table structure.

                               

                              2)  My concern about the above post is that it I believe it will throw off Mike's JavaScript code in the event that one of the fields in RoomEquipment is empty.

                               

                              3)  Even if there are safeguards to prevent missing values, I'd advocate for trying something like:

                               

                                     - Listing a calculated field in RoomEquipment (which returns a string that can be interpreted as JavaScript -- probably it would be a single array entry)

                               

                                            * or *

                               

                                     - Using ExecuteSQL to get at the data, and see if it's possible doctor up the query with the concatenation operator and some literal strings to yield output that can be interpreted as useful JavaScript

                               

                               

                               

                              HTH,

                               

                              -steve

                              • 12. Re: Need to find the full string based on searching for part of it.
                                madmike6537

                                Hadn't thought about using execute SQL in a call field, that might just work I'll give it a try and report back.

                                • 13. Re: Need to find the full string based on searching for part of it.
                                  steve_ssh

                                  Excellent!  Glad to hear that you are working your way through it...

                                   

                                  Best,

                                   

                                  -steve

                                  • 14. Re: Need to find the full string based on searching for part of it.
                                    madmike6537

                                    So I changed my method to the ExecuteSQL and I have it all grabbing the data I want, but I cant seem to figure out how to output my found data into an array - any ideas?  I need it to be able to be read in my javascript code as an array.

                                    1 2 Previous Next