August 31, 201510 yr 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
August 31, 201510 yr 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, 201510 yr by comment
September 1, 201510 yr 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
September 1, 201510 yr 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, 201510 yr by comment
September 4, 201510 yr 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 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?
September 4, 201510 yr 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 .
Create an account or sign in to comment