# string.split()

The `string.split()` function returns comma-separated list of substrings of [`$string`](#usdstring) that are separated by [`$separator`](#usdseparator). The separators aren’t included in these substrings.

{% code lineNumbers="true" %}

```scss
// Sass.
@use 'sass:list';
@use 'sass:string';

// The `string.split()` function.
@function split($string, $separator, $limit: null, $bracketed: false) {
  $result: list.join((), (), comma, $bracketed);
  $index: 0;
  $i: 1;
  @while $index != null {
    $index: string.index($string, $separator);
    @if $index {
      $result: list.append($result, string.slice($string, 1, $index - 1));
      @if $limit and $limit == $i {
        $result: list.append($result, string.slice($string, $index + 1, -1));
        $index: null;
      } @else {
        $string: string.slice($string, $index + 1);
      }
    } @else {
      $result: list.append($result, $string);
    }

    $i: $i + 1;
  }
  @return $result;
}
```

{% endcode %}

{% embed url="<https://github.com/angular-package/sass/blob/main/string/_string.split.function.scss>" %}

### Parameters

#### **`$string`**

The `string` that is split by [`$separator`](#usdseparator).

#### `$separator`

The separator that splits the [`$string`](#usdstring) into the returned list.

#### **`$limit: null`**

Limit split of [`$string`](#usdstring).

#### **`$bracketed`**

Returns bracketed list.

### Return

The return value is a list separated by [`$separator`](#usdseparator) limited by [`$limit`](#usdlimit-null) times, and/or is [`$bracketed`](#usdbracketed).

## Examples

```scss
// Use.
@use '@angular-package/sass/string';

// Examples.
@debug string.split('aaa bbb ccc', ' '); // "aaa", "bbb", "ccc"
@debug string.split('aaa-bbb-ccc', '-'); // "aaa", "bbb", "ccc"
@debug string.split('aaa/bbb/ccc', '/'); // "aaa", "bbb", "ccc"
@debug string.split("Segoe UI Emoji", " "); // "Segoe", "UI", "Emoji"
@debug string.split("Segoe UI Emoji", " ", $limit: 1); // "Segoe", "UI Emoji"
@debug string.split("Segoe UI Emoji", " ", $limit: 1, $bracketed: true); // ["Segoe", "UI Emoji"]
@debug string.split("SF Mono Segoe UI Mono Roboto Mono", " ", $limit: 2, $bracketed: true); // ["SF", "Mono", "Segoe UI Mono Roboto Mono"]

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.angular-package.dev/sass/string/string.split.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
