# split (Shared)

> Splits a text into pieces at the separators.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Data and utilities
- **URL**: https://wiki.mymp.gg/en/split

## Syntax

```lua
table split(string text, string|int separator)
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `text` | `string` | The text. Only up to its first null byte counts. |
| `separator` | `string\|int` | The characters that separate, or a character's code. |

## Returns

A list with the pieces. Empty pieces are left out.

## Example

```lua
local parts = split("2495.1,-1687.4,14.5", ",")
local x, y, z = tonumber(parts[1]), tonumber(parts[2]), tonumber(parts[3])
```

### Note

Each character of the separator splits on its own: `split("a, b", ", ")` cuts at the comma and at the space.

## See also

- [toJSON (Shared)](https://wiki.mymp.gg/en/toJSON.md): Turns a Lua value into JSON text. It is the same function as json.encode.
