May 4, 200718 yr Hi, I'm working on a "highlight search terms" feature and need to figure out the best way to parse the user-inputted search string into a list of separate values. A sample search string might look like: dog tree "bank robber" pole "bell hop" I need to break that down into: dog tree bank robber pole bell hop (with carriage returns after each, i.e. a list of values.) I was thinking of doing this with a looping script & use of Substitute(), but am wondering if anyone can suggest a faster and more direct approach via a custom function. Is it even possible to do that within a custom function? --- On a related subject, I'd also like to make a custom function that will take all of the above values (search terms), and go through a large field of text, and compile a matrix of start & stop positions for each value within the text. I would then use these start & stop positions to drive the Set Selection() script step to allow the user to hop to each occurrence of the found term. Again, is this possible to do in a custom function, or do I have to use a script & loop through to do this? Thank you for your reply!
May 4, 200718 yr To hilight search terms, have a look at this file: FilterText (look at the 'Advanced' example, it should give you a clue. As to do what you're asking, I think I would do it with a recursive function storing the number of " it has met during previous iterations, and inserting a ¶ or not.
May 4, 200718 yr Author Thank you much for the reply. I did look at the sample file you linked to but couldn't figure it out. If you or anyone else wants to give me a bit more of a hint, I'd appreciate it. I've got the text style / highlighting of the search terms down. The problem I can't get past is how to convert the one-line search string (shown in the top of this thread) to the separated list of values I need (also shown in the top of this thread.) Thank you again.
May 5, 200718 yr I tried this too, much tougher than I thought to handle smart quotes being turned on (which I normally like). StringList.zip
May 5, 200718 yr Author I appreciate both of your works. However, Fabrice, I wanted to get the results without quotation marks. (See my original example at top of post.) Thank you again.
May 5, 200718 yr Yes, that's the point with version 2. to manage smart quotes, add this _str = Substitute ( string ; [ "“" ; """ ] ; [ "”" ; """ ] ; [ "" " ; """ ] ; [ "" " ; """ ] ) as first parameter of Let function, and then use _str instrad of string.
May 5, 200718 yr Shawn, can I ask you why you embed a recursive function in a not recursive one ? is it a matter of speed ? Just curious.
May 5, 200718 yr Here is an example for hilighting search terms. Hope you'll find it useful. HilightSearchTerms.fp7.zip
May 5, 200718 yr The recursive call is embedded in another to make the inner one tail recursive, which FileMaker implements more efficiently, and you get 50K calls instead of only 10K before it returns an error. See: http://en.wikipedia.org/wiki/Tail_Recursion Edited May 5, 200718 yr by Guest Clarify question being responded to.
Create an account or sign in to comment