What is the find_any() function in Euphoria?

Overview

This function carries out a search on a set of value. With the find_any() method we can easily locate any value inside another set of values and return the index of such value in the other value.

What does the find_any() function do?

  • It takes in two variables as arguments.
  • It searches for any of the values in the first variable in the second.
  • It returns the index location of any value of the first values that was first found in the second variable.
  • We can easily use it for conditional statements. For instance, we can say if any value from a set of value is found in another value let an action take place.

Syntax

find_any(needle, haystack,start)

Parameters

  • needle: This is the set of values, usually of an object data type, which are to be searched for and maybe found in another variable the haystack parameter.
  • haystack: This is a sequence variable which is going to be traversed in search of another variable the needle.
  • start: This is an index in the haystack where the search can begin. It is optional and when not provided the search starts from the first index.

Return value

Returns the index of the first value of the needle parameter to be found in the haystack parameter. If it’s not found, zero is returned.

Example

In the code example below we’ll find any of the indicated values in another variable.

Note: You have to include the search.e file from the standard modules library to use this function.

include std/search.e
sequence to_be_searched
sequence find_this1, find_this2
find_this1 = "uzwo"
find_this2 = "sio"
to_be_searched = "This is a soccer pitch and some kits"
print(1,find_any(find_this1, to_be_searched))
puts(1,"\n")
print(1, find_any(find_this2, to_be_searched, 15))
puts(1,"\nValue can\'t be found, zero is returned: ")
print(1,find_any("me", "books"))

Explanation

  • Line 1: We import the search.e file.
  • Lines 2–3: We declare some variables.
  • Lines 6–8: We assign values to declared variables.
  • Lines 10–14: We use the find_any() function and print the output to the screen.

Free Resources