Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

elixir

How to split a string in Elixir

Abhilash

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 split() method is used to split a string based on the given pattern.

Syntax

String.split(str, pat)

Parameters

  • str: The string to split.
  • pat: The pattern to use to split the string. The pattern can be a regex or a string.

Return value

The method returns a list.

Code

string = "hello educative"
pattern = "\s"
split_string = String.split(string, pattern)
IO.inspect split_string
Splitting string in Elixir

Explanation

  • Line 1: We define the string to be split.
  • Line 2: We define the pattern to use.
  • Line 3: We split the string into substrings based on the given pattern using the String.split() method.
  • Line 4: We print the list returned after the split.

RELATED TAGS

elixir

CONTRIBUTOR

Abhilash
Copyright ©2022 Educative, Inc. All rights reserved

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