Newbies tomtill Posted November 22, 2009 Newbies Posted November 22, 2009 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?
comment Posted November 22, 2009 Posted November 22, 2009 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".
Max Heller Posted November 25, 2009 Posted November 25, 2009 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 )
Recommended Posts
This topic is 5545 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