What is the remove() method in Euphoria?

Overview

The remove() method is built-in Euphoria’s standard library. This method removes characters whose index is the same as that of the start and stops points of the replacement as indicated from a sequence.

In the remove() method, we can target some characters or sub-sequence in a nested sequence at a particular position in such a sequence and remove them.

Syntax

remove(removeFrom, startFrom,endAt)

Parameters

  • removeFrom: This is the sequence to be removed from.

  • startFrom: This is an integer indicating the sequence’s point to start the replacement from. This argument is required.

  • endAt: This parameter is optional, as it defaults to the start value when not provided. It is an integer value that indicates the point in the sequence to stop the removal.

Return value

The value returned is the sequence with some elements removed compared to the original.

Note: Whitespaces in the sequence are also counted as part of the characters to be removed.

--declare variables
sequence mySeq1, mySeq2
---assign variables
mySeq1 = "To remove some word starting from one point"
--using the remove method, remove from index 3 to 12
mySeq2 = remove(mySeq1, 3, 12)
--print outcome to screen
printf(1,"%s",{mySeq2})

Explanation

  • Line 3: We declare variables.

  • Line 6: We assign values to the declared variables.

  • Line 9: We use the remove method to remove characters from index 3 to 12, including spaces.

  • Line 12: We print the outcome to screen.

We can remove the third parameter, the endAt parameter, and check what the outcome would look like.

Free Resources