a concise shot of dev knowledge
Become a Contributor
Concise shots of dev knowledge

RELATED TAGS

euphoria
communitycreator

What is the split() method in Euphoria?

NDUKWE CHIDERA K.

Overview

In Euphoria, split() is an inbuilt function that changes the shape of a Euphoria sequence.

As the name implies, the split() method breaks up a sequence, using a defined separator into chunks of indicated length and amount.

Note: This function may be applied to a string or complex sequence. You may apply this function to a string sequence or a complex sequence.

Syntax

split(target,delimiter,remove_empty,limit)


Parameters

• target: This is the sequence value that will be split.

• delimiter: An object and an optional parameter with a default value of 0 that separates the split chunks.

• remove_empty: This is an integer with a default value of 0, indicating that zero-length subsequence in the split outcome should not be ignored. In contrast, any other integer value will cause a zero-length subsequence to be ignored.

• limit: This integer variable puts a cap on the number of the split chunk to be returned. The default is zero, which means all split chunks should be returned.

Return value

This function returns a sequence, with subsequences, all from splitting the target.

Example

include std/sequence.e

sequence target2 = {5,1,2,3,1,3,4,1,6,7,8}
object delimiter = 1
integer remove_empty = 0
integer limit = 4

sequence output = split(target2,  delimiter, remove_empty, limit)
print(1,output)
Implementation of splitting

Explanation

In the above example, integer 1 was used as the delimiter, and a limit of 4 was used. This caused the target to be split at any point; the integer 1 was found for as many as 4 occurrences, producing the outcome we have in our output.

• Line 1: We include the necessary module.
• Line 3–6: We define variables that will be passed as arguments to the split function.
• Line 8: We call the split() method and save its output.
• Line 9: We print the ouput to the console.

RELATED TAGS

euphoria
communitycreator

CREATOR

NDUKWE CHIDERA K.
RELATED COURSES

View all Courses

Keep Exploring

Learn in-demand tech skills in half the time

Copyright ©2022 Educative, Inc. All rights reserved.