Jump to content
Server Maintenance This Week. ×

search string by value list


This topic is 5273 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • 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?

Link to comment
Share on other sites

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

)

Link to comment
Share on other sites

This topic is 5273 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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