# string.index()

The `string.index()` function returns index or list of indexes of [`$substrings`](#usdsubstrings...).

{% code lineNumbers="true" %}

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

// The `string.index()` function.
@function index($string, $substring, $substrings...) {
  @if type-of($string) == string {
    $result: ();
    @each $substring in list.join($substring, $substrings, comma) {
      $result: list.append(
        $result,
        if(
          meta.type-of($substring) == string,
          string.index($string, $substring),
          null
        ),
        comma
      );
    }
    @if list.length($result) > 0 {
      @return if(list.length($result) == 1, list.nth($result, 1), $result);
    }
  }
  @return null;
}
```

{% endcode %}

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

### Parameters

#### `$string`

The value to check whether it contains given [`$substring`](#usdsubstring) and/or [`$substrings`](#usdsubstrings...).

#### `$substring`

A substring to find in [`$string`](#usdstring).

#### `$substrings...`

The list of substrings to find in [`$string`](#usdstring).

### Return

The return value is the index or list of indexes of the given found substrings.

## Examples

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

// Examples.
// Single
@debug string.index("Helvetica Neue", "Helvetica"); // 1
@debug string.index("Helvetica Neue", "Neue"); // 11

// Multiple
@debug string.index("Helvetica Neue", "Helvetica", "Neue"); // 1, 11
@debug string.index("Helvetica Neue", "Helvetica", "Neue", "Wrong"); // 1, 11, null
@debug string.index("Helvetica Neue", "Helvetica", "Neue", "Wrong", true); // 1, 11, null, null

// Different type of the `$string`
@debug string.index(true, "Helvetica"); // null

```


---

# 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.index.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.
