# Manipulate text

> Run a function on some text or a list, and keep the result.

Source: https://docs.buildcord.dev/nodes/variables-and-data/manipulate-text/

`data.text` changes text with a function and saves the result for this run. It can't fail.

## Settings

| Setting | What it does |
| --- | --- |
| Text | The input, such as `{option.name}`. |
| Function | What to do. See the tables. |
| With | The function's argument, when it takes one. |
| Save as | The name to keep the result under. The default is `result`. |

### Text

| Function | What it does | **With** holds |
| --- | --- | --- |
| Uppercase, Lowercase, Capitalise, Title case | Changes the case. Title case capitalises every word. | Nothing |
| Trim | Removes spaces from both ends. | Nothing |
| Replace | Replaces text. | `from,to` |
| Slice | Keeps part of the text. | `start,end` |
| Truncate | Cuts it to a length, ending with …. | The most characters |
| Pad the start, Pad the end | Fills it out to a width: `7` becomes `007`. | `width,character`. A number is padded with zeros unless you say. |
| Split | Splits into a list. | The separator |
| Length, Word count | Counts characters, or words. | Nothing |
| Reverse | Reverses the text. | Nothing |
| Repeat | Repeats the text. | How many times |
| Pull out a pattern | Keeps the first match of a regular expression, or its first group: `order #(\d+)` gives the number. | The pattern |
| Remove a pattern | Removes every match. | The pattern |
| Encode for an address | Makes text safe to put in a URL. | Nothing |

### Numbers and time

| Function | What it does | **With** holds |
| --- | --- | --- |
| Format a number | Separates thousands: `1234567.8` is `1,234,567.8`. | Decimal places, or `short` for `1.2M` |
| Draw as a bar | Draws a fraction from 0 to 1 as blocks. | How many blocks wide |
| Read as a length of time | Turns text such as "2d 6h" into seconds, or nothing if it can't be read. | Nothing |

### Lists

A list is separated by commas, or by lines when it has more than one line.

| Function | What it does | **With** holds |
| --- | --- | --- |
| Count the items in a list | Counts items, blanks left out. | `newline` to count lines instead of commas |
| Item of a list | One item, by position. | From 1, or from -1 for the last |
| Sort a list | Sorts it, numbers as numbers. | `desc` for largest first |
| Drop repeats from a list | Keeps the first of each, ignoring capitals. | Nothing |
| Shuffle a list | Puts it in a random order. | Nothing |
| Join a list | Joins the items with something between. | What goes between, or `newline` |

## Ways out

`out`.

## Produces

`{temp.name}`, using the name from **Save as**.

## Example

Show a leaderboard's score with separators: **Format a number** on `{row.score}` with `0`.

## Related

- [Work out an equation](https://docs.buildcord.dev/nodes/variables-and-data/work-out-equation)
- [Change a list](https://docs.buildcord.dev/nodes/variables-and-data/change-list)
