Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

method
euphoria
communitycreator
match

What is the match() method in Euphoria

NDUKWE CHIDERA K.

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The match() method is a part of the standard library in Euphoria and it searches one variable for a match with another.

The match() method

  • Accept two variables as parameters.
  • The first of these two parameters will serve as the search word.
  • The match for the search word is checked for in the second variable which is the search stack.

Syntax

match(search_word,search_stack,start_point)

Parameters

  • search_word: This can be an atom or a substring whose match is being checked for in the search_stack.

  • search_stack: This is the sequence that will be checked, to see if any slice from it matches with the search_word.

  • start_point: This is an integer and an optional parameter that indicates where the search for the search_word in the search_stack should begin. By default, it starts at 1.

Return value

If any part of the search_stack matches the search_word, the method returns the smallest index of the search_word in the search_stack, otherwise it returns 0.

Code

--declare some sequence variables
sequence searchWord1,searchWord2
--declare some atom variables to hold our results
atom output1, output2
searchWord1 = "hing"
searchWord2 = "pin"
output1 = match(searchWord1,"Things will do as used")
output2 = match(searchWord2,"Educative, byte sized shots")
--another random example
printf(1, "\n %d", match({2},{4, 5, 6, .7, 2}))
printf(1, "\n %d", output1)
printf(1, "\n %d", output2)

Explanation

  • Lines 2 and 5: We declare some variables.

  • Lines 7 and 8: We assign values to the variables declared earlier.

  • Lines 10 and 11: We call the match() function to check if a match can be found amongst the provided variables.

  • Lines 14–16: We use the printf() method to print the output to the screen.

RELATED TAGS

method
euphoria
communitycreator
match

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring