Contains Keyword (from) File

2 posts / 0 new
Last post
tongb
Offline
Joined: 10/04/2017 - 10:58
Contains Keyword (from) File

The financial auditors in my office needed a way to search for a variety of keywords in a field of a dataset. The needed different keywords for different tests. They also wanted to see which keyword matched in its own column.
 
Usage:
 
#Contains_Keyword_File( SEARCHFIELD, "filename.txt" )
 
This function searches the SEARCHFIELD for any keyword in the supplied file and returns the keyword that was found, or an empty string is nothing was found. The text file should contain one keyword per line. The search is case insensitive. The search locates substrings, so searching for "app" will match on "happiness" in the data.
 
IDEA will look for the file in the current project folder. If you want to locate the file elsewhere, add a path to the filename parameter. Example:
 
#Contains_Keyword_File( SEARCHFIELD, "Other.ILB\filename.txt" )
 
Notes:
 
I'm not thrilled that the code has to open and close the keyword file everytime the function is invoked, but I've not found a mechanism in IDEA where I might be able to load the keywords into a cache that persists between function calls. Suggestions are welcome.
 
This function was partially inspired by the "Text Search" script found elsewhere on this site.

Brian Element's picture
Brian Element
Online
Joined: 07/11/2012 - 19:57

Hi tongb,

That is a nice Custom Function.  Unfortunately you can't save variables between uses, so each time it reads a new row it will access the text file.  The only way to get around this would be through an IDEAScript in which you could place the items you are searching for into an array.

Brian