Jump to content
Sign in to follow this  
anachron

Parse search string - Looping script or custom function?

Recommended Posts

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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Shawn,

can I ask you why you embed a recursive function in a not recursive one ? is it a matter of speed ?

Just curious.

Share this post


Link to post
Share on other sites

I would think more a matter of convenience.. though i haven't looked at the file.

Share this post


Link to post
Share on other sites

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 by Guest
Clarify question being responded to.

Share this post


Link to post
Share on other sites

Thank you. The link was very interesting too. Thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site, you agree to our Terms of Use.