# ee.String.index

Searches a string for the first occurrence of a substring. Returns the index of the first match, or -1.

<br />

| Usage | Returns |
|---|---|
| `String.index(pattern)` | Integer |

| Argument | Type | Details |
|---|---|---|
| this: `target` | String | The string to search. |
| `pattern` | String | The string to find. |

## Examples

### Code Editor (JavaScript)

```javascript
print(ee.String('abc123').index(''));  // 0
print(ee.String('abc123').index('c1'));  // 2
print(ee.String('abc123').index('ZZ'));  // -1

// index is case-sensitive.
print(ee.String('abc123').index('BC'));  // -1
```
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('abc123').index(''))  # 0
display(ee.String('abc123').index('c1'))  # 2
display(ee.String('abc123').index('ZZ'))  # -1

# index is case-sensitive.
display(ee.String('abc123').index('BC'))  # -1
```