sal88 Posted August 31, 2015 Posted August 31, 2015 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
comment Posted August 31, 2015 Posted August 31, 2015 (edited) 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 August 31, 2015 by comment
sal88 Posted September 1, 2015 Author Posted September 1, 2015 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
comment Posted September 1, 2015 Posted September 1, 2015 (edited) 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 September 1, 2015 by comment
sal88 Posted September 4, 2015 Author Posted September 4, 2015 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 breakCase ( 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 wordCase ( 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?
comment Posted September 4, 2015 Posted September 4, 2015 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 .
Recommended Posts
This topic is 3437 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 accountSign in
Already have an account? Sign in here.
Sign In Now