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.

Filter by length and case

Featured Replies

Hi all

I've been searching high and low for a custom function but to no avail. 

Is there a way to search a text field for all words of a particular length and case? e.g. 5 characters and upper case.

Thanks

 

Is there a way to search a text field for all words of a particular length and case? e.g. 5 characters and upper case.

If by "search" you mean "extract", try something like:

ExtractWords ( text ) =

Let ( [
word = LeftWords ( text ; 1 ) ;
countWords = WordCount ( text )
] ;
Case ( Length ( word ) = 5 and Exact ( word ; Upper ( word ) ) ; word & ¶ )
&
Case ( 
countWords > 1 ; 
ExtractWords ( RightWords ( text ; countWords - 1 )  )
)
)

Given an input of:

Alpha BRAVO Charlie DELTA ECHO Foxtrot

the result will be:

BRAVO
DELTA

i.e. a return-separated list of all words in text that are exactly 5 characters long and all in uppercase.

 

 

Edited by comment

  • Author

How do you do that?! Lol, I'm going to spend some time deconstructing that...I can never seem to get my head around these fancy custom functions.

Thanks so much comment, incredibly helpful as per usual :)

 

I can never seem to get my head around these fancy custom functions.

There's nothing "fancy" here: you want to go over each word in the given text, so you start with the first word, process it, and then call the function again with the rest of the words - so that the second word becomes the first one on the next call and so on, until you run out of words. You'd do well by spending some time "deconstructing" this, because this is the most common algorithm for a recursive custom function.

 

 

Edited by comment

  • Author

OK I think I've got my head around it. This is a recursive function right? That's probably the aspect that confuses me.

Would you be able to tell me if I've got the right idea:

Let ( [
word = LeftWords ( text ; 1 ) ;
countWords = WordCount ( text )
] ;

//If the first word of 'text' is 5 characters and Upper case, then display that word and a carriage break
Case ( Length ( word ) = 5 and Exact ( word ; Upper ( word ) ) ; word & ¶ )
&
//If 'text' has more than one word, then apply this function again but with the first word trimmed off. 'text', after the initial run through, is defined recursively, each iteration trimming off the first word
Case ( 
countWords > 1 ; 
ExtractWords ( RightWords ( text ; countWords - 1 ))))


So in a sense, the function is only actually pulling in the first word (if the criteria is met) of the 'text' parameter. The part after the ampersand is only redefining the 'text' parameter?

How does it know to exit the recursion? 

Yes, that is a correct perception of how it works.

How does it know to exit the recursion? 

The recursive call is conditional: it only happens when countWords > 1 .

  • Author

Ah yes. Thanks comment!

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

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.