Skip to main content

split ()

Divides a string into a list of substrings.

Parameters

$string
The source string to divide into a list of substrings.
Type
String
$delimiter
The delimiting string which separates each substring to be included in the list.
Type
String | Null
Default
null
$limit
A non-negative integer specifying a limit on the number of substrings to be including in the list.
Type
Number | Null
Default
null
$separator
The type of separator to be used by the returned list.
Type
space | comma | slash | auto
Default
auto
$bracketed
Whether the returned list has square brackets or no brackets.
Type
Boolean | auto
Default
auto

Return Value

List
A list of strings, split at each point where the delimiter occurs in the given string.

Example

@use '@sass-fairy/string';

$str: 'The quick brown fox jumps over the lazy dog.';

@debug string.split($str);
// 'The quick brown fox jumps over the lazy dog.'

@debug string.split($str, ' ');
// 'The' 'quick' 'brown' 'fox' 'jumps' 'over' 'the' 'lazy' 'dog.'

@debug string.split($str, '', 3);
// 'T' 'h' 'e'

@debug string.split($str, 'o', $separator: 'comma', $bracketed: true);
// ['The quick br', 'wn f', 'x jumps ', 'ver the lazy d', 'g.']