There are a good number of functions in the search.e
library that use different types of algorithms to carry out some form of a search operation. Such search operations are usually geared toward locating some values in another. In this shot, we will learn about the begins
method.
begins()
methodThe begins
method checks if a value can be found at the start of another value. It is a boolean
operation. Therefore, it returns either true
or false
. A return value of true
means that the value being checked for was found at the beginning of another value, and a return value of false
means that the value being checked for was not found at the start of another value.
begins(substring, fullstring)
The presence of the substring
will be checked for at the head of the fullstring
.
substring
: This is a set of characters (sequence) that will be searched for at the start of the fullstring
.
fullstring
: This is a sequence which may or may not contain the substring
being searched for.
The begins
method will return 1
if the substring
is found at the head/start of the fullstring
. Otherwise, it will return 0
.
The code given below shows us the begins()
method in action.
include std/search.eatom result1, result2, result3result1 = begins("ply", "plying that route")result2 = begins("sm", "plasticism")result3 = begins("e", "edpresso")printf(1,"\n %d", result1)printf(1,"\n %d", result2)printf(1,"\n %d", result3 )
Line 1: We add the search library in a file to allow us to use the begins()
method.
Line 3: We declare the variables result1
, result2
, and result3
.
Lines 5–7: We use the begins()
method and store the output in the variables we declared earlier.
Lines 9–11: We display the output using the begins()
method.