What is the splice() method in Euphoria?

In Euphoria, the splice() method is a built-in subroutine used to perform certain operations on a sequence.

This method will bridge a sequence at a particular indicated position, and insert specified data at the position of the bridge.

Simple illustration of a splice operation

The illustration above shows how the splice method introduces a new set of data at the position 2 of the sequence.

Syntax

splice(whatToSplice, spliceWith,splicePosition)

Parameters

  • whatToSplice: This represents the sequence which will be spliced.
  • spliceWith: This represents the data, which will be added to the sequence.
  • splicePosition: This represents the index of the sequence from which the splicing will start.

Return value

It returns a sequence with a length equal to that of whatToSplice, and the length of spliceWith joined together.

Code

--define an object
object result
--define a sequence
sequence splicing
splicing = "My is john"
--invoking the splice function.
result = splice( splicing," name",3)
printf(1,result)

Explanation

  • Line 3: We use an object, result, to save the result of performing a splice on the variable splicing.
  • Line 10: We add the name string to splicing on the third spot in the sequence.
  • Line 11: We print the output of the splice operation.

Free Resources