Jump to content
Server Maintenance This Week. ×

Parse search string - Looping script or custom function?


This topic is 6200 days old. Please don't post here. Open a new topic instead.

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!

Link to comment
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.

Link to comment
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.

Link to comment
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.

Link to comment
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.
Link to comment
Share on other sites

This topic is 6200 days old. Please don't post here. Open a new topic instead.

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
×
×
  • Create New...

Important Information

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