November 22, 200916 yr Newbies What I need is a function that will test whether any member of a value list is in a text string, if true, it should return the value. "the brown cow needs milk" compare to value list "milk toast|jaguar|brown cow|red cow" should return "brown cow" This differs from most requirements in that the value list may contain multiple words, while the text string is a sentence. One option is to explode the text string into a list of each word, followed by pairs of words, followed by phrases of 3., similar to the ExplodeKey custom function for individual words. However, I am having trouble wrapping my head around nested recursive functions, and I don't have time to fully grok it right now. Can someone point me to a custom function that does this? For example, this ExplodeKey (string) Case ( string = "" ; "" ; ExplodeKey ( LeftWords ( string ; Wordcount (string) - 1 ) ) & string & "¶" ) ) will get me a list with the first word followed by each additional word But next I need to lop off the first word, then do it again, then lop of the next word... How do I do this?
November 22, 200916 yr I believe you should recurse on the values of the value list, rather than on the words of the string. However, this may not be enough to eliminate a positive answer when the value list contains "red cow" and text contains "hired coworkers".
November 25, 200916 yr Wrote up a custom function for you. Enjoy! // ValuesFoundInText ( text ; listOfValues ) // // Searches a text string for each value in a list and returns a list of the values that exist in the text // // Parameters: // text - the text to search // listOfValues - a return delimited list of search strings Let( [ numberOfValues = ValueCount( listOfValues ); searchString = GetValue( listOfValues; 1 ); restOfTheValues = RightValues( listOfValues; numberOfValues - 1 ); doneWithValues = not ValueCount( restOfTheValues ); firstPart = Case( PatternCount( text; searchString ); searchString ); thirdPart = Case( not doneWithValues; ValuesFoundInText( text; restOfTheValues ) ); secondpart = Case( ValueCount( firstPart ) and ValueCount( thirdPart ); "¶" ) ]; firstPart & secondPart & thirdPart )
Create an account or sign in to comment