# Slice

| type   | returns      |
| ------ | ------------ |
| Method | \`string\`\` |

## Arguments

| name | type             | description                                                                                                               |
| ---- | ---------------- | ------------------------------------------------------------------------------------------------------------------------- |
| A    | number           | The starting position to slice from                                                                                       |
| B    | number, optional | The position to end the slice. If omitted this slices to the end. If negative, it will refer to the position from the end |

## Explanation

The `.slice` function returns a substring from two given indexes of the original string.

## Examples

```swift
"foo".slice(1, 2) == "o"
"0123".slice(0, -1) == "012"
```


---

# 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.cheddar.vihan.org/docs/standard-library/string/slice.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.
