Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Parse search string - Looping script or custom function?

Featured Replies

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!

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.

  • 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.

I tried this too, much tougher than I thought to handle smart quotes being turned on (which I normally like).

StringList.zip

  • 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.

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.

Shawn,

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

Just curious.

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

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.

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

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.