# ee.String.slice

Returns a substring of the given string. If the specified range exceeds the length of the string, returns a shorter substring.

<br />

| Usage | Returns |
|---|---|
| `String.slice(start, *end*)` | String |

| Argument | Type | Details |
|---|---|---|
| this: `string` | String | The string to subset. |
| `start` | Integer | The beginning index, inclusive. Negative numbers count backwards from the end of the string. |
| `end` | Integer, default: null | The ending index, exclusive. Defaults to the length of the string. Negative numbers count backwards from the end of the string. |

## Examples

### Code Editor (JavaScript)

```javascript
print(ee.String('').slice(0));  // ''
print(ee.String('').slice(-1));  // ''

var s = ee.String('abcdefghijklmnopqrstuvwxyz');
print(s.slice(0));  // abcdefghijklmnopqrstuvwxyz
print(s.slice(24));  // yz
print(s.slice(-3));  // xyz
print(s.slice(3, 3));  // ''
print(s.slice(2, 3));  // c
print(s.slice(-4, 25));  // wxy
```
Python setup

See the [Python Environment](https://developers.google.com/earth-engine/guides/python_install) page for information on the Python API and using
`geemap` for interactive development.

```python
import ee
import geemap.core as geemap
```

### Colab (Python)

```python
display(ee.String('').slice(0))  # ''
display(ee.String('').slice(-1))  # ''

s = ee.String('abcdefghijklmnopqrstuvwxyz')
display(s.slice(0))  # abcdefghijklmnopqrstuvwxyz
display(s.slice(24))  # yz
display(s.slice(-3))  # xyz
display(s.slice(3, 3))  # ''
display(s.slice(2, 3))  # c
display(s.slice(-4, 25))  # wxy
```