Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

euphoria
communitycreator

How does the find_all_but() method work in Euphoria

NDUKWE CHIDERA K.

Overview

To know the position of a particular value in a sequence, we use the find_all_but() search method which is a part of the search.e, a special search-and-find technique.

The find_all_but() method

This function searches a sequence to find all non-occurrences of a variable and returns the indices of such occurrences.

For instance, the variable B = "endear" and find_all_but('e',B) returns the indices of values in B that are not “e”. The output will be {2,3,5,6} excluding indices “1” and “4” where “e” are available.

Syntax

find_all_but(needle_value, haystack_value, start_point)

Parameters

  • needle_value : This parameter is an object variable that will be checked for in the haystack_value.

Note: Make sure the needle_value parameter is a single value enclosed in a single quote.

  • haystack_value: The sequence variable to search and find all non-occurrences of the needle_value.

  • start_point (optional): The point from where the search will start. It is, by default, the integer value of 1.

Example

The code below is a simple illustration of what the find_all_but() function does.

include std/search.e

sequence haystack_value = "letters"

sequence output1, output2 

output1 = find_all_but('s', haystack_value)
output2 = find_all_but('t', haystack_value, 4)
print(1,output1)
puts(1,'\n')
print(1,output2)

Explanation

  • Line 1: We include the search.e file from the standard library into our code.

  • Line 3 and 5: We define and declare variables.

  • Line 7 and 8: We call the find_all_but() method and saved its output in variables.

  • Line 9 and 11: Print the output of the results on the screen.

RELATED TAGS

euphoria
communitycreator
RELATED COURSES

View all Courses

Keep Exploring