Share via


The Filter Function

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The Filter function searches a string array for all elements that match a given text string. The Filter function takes three arguments: a string array, a string containing the text to find, and a constant specifying the string-comparison method. It returns a string array containing all the matches that it finds.

You can use the Filter function to determine whether a particular element exists in an array. An example, the ConvertToProperCase procedure, appears in Converting Strings.

When working with the Filter function, you might notice that it returns a particular element even if only part of the element matches the search text. In other words, if your search text is the letter "e," and the array you're searching contains the element "test," the array returned by the Filter function will contain the element "test."

Given this behavior, you might be tempted to use the Filter function to rewrite the CountOccurrences procedure shown earlier in this section. Before doing so, bear in mind that the CountOccurrences procedure counts every occurrence of a particular character in a string, even if there is more than one occurrence in a word. When you are using the Filter function, on the other hand, you can count an occurrence only once per element, even if the character occurs twice within a single element in the array.

See Also

Working with Strings as Arrays | The Split Function | The Join Function