# Text

> Edit, split, join, search, and check text.

Built-in step · 24 steps. Web page: https://docs.lodol.com/docs/integrations/built-in/text

## Steps

### Check end of text

Check whether text ends with specific words or characters.

**Inputs**

- Text (`text`, text, required): The text to check.
- Ends with (`suffix`, text, required): The text it should end with, such as .pdf.
- Case sensitivity (`case_sensitive`, true/false): Match upper- and lower-case letters exactly (the default). Turn this off to treat them as the same. Default: `true`.

**Outputs**: Whether the text ends with the text given.

**Example output**

```json
true
```

### Check if text includes

Check whether text includes specific words or characters.

**Inputs**

- Text to search through (`text`, text, required): The text to search through.
- Text to find (`substring`, text, required): The exact text to look for.
- Case sensitivity (`case_sensitive`, true/false): Match upper- and lower-case letters exactly (the default). Turn this off to treat them as the same. Default: `true`.

**Outputs**: Whether the text includes the text searched for.

**Example output**

```json
true
```

### Check start of text

Check whether text starts with specific words or characters.

**Inputs**

- Text (`text`, text, required): The text to check.
- Starts with (`prefix`, text, required): The text it should start with.
- Case sensitivity (`case_sensitive`, true/false): Match upper- and lower-case letters exactly (the default). Turn this off to treat them as the same. Default: `true`.

**Outputs**: Whether the text starts with the text given.

**Example output**

```json
true
```

### Convert HTML to Markdown

Turn HTML, like an email's body or a web page, into Markdown that reads as plain text and keeps its headings, lists, links, bold and italic, tables and code: ready for an AI step, a Slack message or a note. Scripts and styles are left out.

**Inputs**

- HTML (`text`, text, required): The HTML to convert, a whole page or a piece of one.

**Outputs**: The Markdown.

**Example output**

```json
"# Hello\n\nSome **bold** text."
```

### Convert JSON to XML

Turn data or JSON text into an XML document, for an API or a service that speaks XML, a feed or a file: each field becomes an element named after it, a list repeats its element, and a field named like @id becomes an attribute.

**Inputs**

- Data (`data`, text, required): The data to write as XML: a record or a list from an earlier step, or JSON text.
- Root element (`root`, text): The name of the element that wraps everything, like order or request. Defaults to root. Default: `root`.

**Outputs**: The XML document, indented, with an XML declaration on its first line.

**Example output**

```json
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<order id=\"1042\">\n  <customer>Jordan Lee</customer>\n  <total>84.00</total>\n</order>"
```

### Convert Markdown to HTML

Turn Markdown, like an AI step's answer or a template you write, into plain HTML for a web page, a rich-text field or an app that takes HTML: headings, lists, links, bold and italic, tables and code all come through. For an email, use HTML's Turn text into HTML, which adds the styles email apps show.

**Inputs**

- Markdown (`text`, text, required): The Markdown to convert. A line break in it is a line break in the HTML, and HTML tags in it pass through.

**Outputs**: The HTML, without <html> or <body> around it and with no styles, ready to put in a page or a field.

**Example output**

```json
"<h1>Hello</h1>\n<p>Some <strong>bold</strong> text.</p>"
```

### Convert XML to JSON

Turn XML, like an API's response or a feed, into data whose fields later steps can use, the way Read a file reads an XML file: each element is a field named by its tag, a tag that repeats is a list, and attributes are fields too.

**Inputs**

- XML (`text`, text, required): The XML to convert.

**Outputs**: What the outermost element holds: a record of its elements and attributes, or its text when it holds only text. Text stays text, so a number in the XML is text like "3".

**Example output**

```json
{
  "order": [
    {
      "customer": "Jordan Lee",
      "id": "1042",
      "total": "84.00"
    },
    {
      "customer": "Sam Rivera",
      "id": "1043",
      "total": "12.50"
    }
  ]
}
```

### Count characters

Count how many characters are in text.

**Inputs**

- Text (`text`, text, required): The text to measure.

**Outputs**: The number of characters in the text.

**Example output**

```json
13
```

### Count words

Count how many words are in text.

**Inputs**

- Text (`text`, text, required): The text whose words are counted.

**Outputs**: The number of words in the text.

**Example output**

```json
9
```

### Encode or decode text

Make text safe to put in a web address, HTML or JSON, encode or decode Base64, or remove accents and emoji.

**Inputs**

- Text (`text`, text, required): The text to encode or decode.
- Change it to (`encoding`, text, required): How to change the text. One of: `url_encode` (Safe for a web address (a b → a%20b)), `url_decode` (Back from a web address (a%20b → a b)), `base64_encode` (Base64), `base64_decode` (Back from Base64), `html_escape` (Safe for HTML (< → &lt;)), `html_unescape` (Back from HTML (&lt; → <)), `json_escape` (Safe inside JSON text), `plain_ascii` (Plain letters, no accents or emoji). Default: `url_encode`.

**Outputs**: The text, encoded or decoded.

**Example output**

```json
"Hello%20world"
```

### Extract from text

Pull matches out of text: an email address, web address, phone number, domain, number, or your own pattern.

**Inputs**

- Text (`text`, text, required): The text to search, such as the body of an email.
- Extract (`type`, text, required): What to pull out of the text. One of: `email` (Email address), `url` (Web address), `phone` (Phone number (+14155550123)), `domain` (Domain (example.com)), `path` (Web address path (/blog/post)), `number`, `pattern` (Custom pattern). Default: `email`.
- Custom pattern (`pattern`, text): A regular expression to search for. Used only when Extract is set to Custom pattern. Only when Extract is Custom pattern.
- Return (`all_matches`, true/false): Return only the first match, or every match as a list. Default: `false`.
- Country (`region`, text): The country of phone numbers written without a country code. Defaults to the United States. Only when Extract is Phone number (+14155550123). Default: `US`.

**Outputs**: The first match, or a list of every match when all matches are asked for. Numbers come back as numbers, and finding nothing gives empty text, or an empty list.

**Example output**

```json
1234.5
```

### Format phone number

Write a phone number one standard way, however it was typed, like +1 415-555-0123 or +14155550123 for a texting app.

**Inputs**

- Phone number (`text`, text, required): The phone number, written any way.
- Write it as (`style`, text, required): How to write the number. One of: `international` (International (+1 415-555-0123)), `e164` (For apps (+14155550123)), `national` (National ((415) 555-0123)). Default: `international`.
- Country (`region`, text): The country of numbers written without a country code. A number that starts with its own, like +44, is read in that country instead. Defaults to the United States. Default: `US`.

**Outputs**: The phone number, written the chosen way.

**Example output**

```json
"+1 415-555-0123"
```

### Format text

Change the letter case of text: make it uppercase, lowercase, capitalize the first letter, use title or sentence case, or turn it into a slug for a web address.

**Inputs**

- Text (`text`, text, required): The text to change the letter case of.
- Format as (`case`, text, required): How the text should be cased. One of: `uppercase` (Uppercase (HELLO WORLD)), `lowercase` (Lowercase (hello world)), `capitalize` (Capitalize first letter (Hello world)), `title` (Title case (Hello World)), `sentence` (Sentence case (Hello world. Bye now.)), `slug` (Web address slug (hello-world)). Default: `uppercase`.

**Outputs**: The text in the chosen letter case.

**Example output**

```json
"Hello World"
```

### Get part of text

Take a piece of text: what comes before or after a word or character, what sits between two, or a number of characters from a position. For example, the name before the @ in an email address.

**Inputs**

- Text (`text`, text, required): The text to take a part of.
- Take (`part`, text, required): Which part of the text to take. One of: `before` (The text before), `after` (The text after), `between` (The text between), `characters` (Characters by position). Default: `after`.
- Look for (`marker`, text): The word or characters to look for, like @ or Order #. Letter case doesn't matter, and the first one found is used. Only when Take is The text before, The text after or The text between.
- Up to (`end_marker`, text): Where the part ends: the next time this appears after the text looked for. Only when Take is The text between.
- From position (`start`, number): The first character to take: 1 is the first character, -1 the last, -4 the fourth from the end. Only when Take is Characters by position. Default: `1`.
- Number of characters (`count`, number): How many characters to take. Leave empty for the rest. Only when Take is Characters by position.

**Outputs**: The part of the text, without spaces around it. Blank text when what was looked for isn't there.

**Example output**

```json
"ana"
```

### Join list into text

Turn a list into one piece of text.

**Inputs**

- List (`items`, list, required): The list of values to combine into one piece of text.
- Put between items (`separator`, text, required): Use empty text to join with nothing.

**Outputs**: The list's items as one piece of text, with the separator between each.

**Example output**

```json
"red, green, blue"
```

### Look up a value in a table

Turn one value into another with a small table you fill in, like US to United States or a status code to a label, instead of a chain of If steps.

**Inputs**

- Value to look up (`value`, text, required): The value to find in the table, like a country code.
- Table (`table`, object, required): Each value to look for, and what to give back for it. Letter case and spaces around a value don't matter.
- If nothing matches (`fallback`, text): What to give back when the value isn't in the table. Leave empty to get a blank.
- Case sensitivity (`case_sensitive`, true/false): Match upper- and lower-case letters exactly. Off by default, so us, US and Us all match. Default: `false`.

**Outputs**: What the table gives for the value, the fallback when it isn't there, or a blank without one.

**Example output**

```json
"United States"
```

### Match keywords

Score text against your keyword lists to see how well it matches. Useful for tagging, filtering, or deciding what should happen next.

**Inputs**

- Text (`text`, text, required): The text to score. Letter case is ignored.
- Strong keywords (`strong_terms`, list, required): Most important words or phrases. Each match adds 3 points.
- Medium keywords (`medium_terms`, list): Fairly important words or phrases. Each match adds 2 points.
- Weak keywords (`weak_terms`, list): Minor words or phrases. Each match adds 1 point.
- Score needed to pass (`threshold`, number): Total points needed to count as a match. Defaults to 3. Default: `3`.

**Outputs**: Whether the text matched, its score, and which keywords it contains.

- `is_match` (true/false): Whether the score reached the score needed.
- `matched_terms` (list): The keywords found, strong ones first, each with the list it came from.
- `score` (number): 3 points for each strong keyword found, 2 for each medium one, and 1 for each weak one.

**Example output**

```json
{
  "is_match": true,
  "matched_terms": [
    {
      "term": "we're hiring",
      "tier": "strong"
    },
    {
      "term": "join our team",
      "tier": "medium"
    },
    {
      "term": "engineer",
      "tier": "weak"
    }
  ],
  "score": 6
}
```

### Read JSON text

Turn JSON written as text, like an AI step's answer or a webhook body, into data whose fields later steps can use.

**Inputs**

- JSON text (`text`, text, required): The text holding the JSON. It may be wrapped in a code block or a sentence.

**Outputs**: The data the JSON holds, usually a record or a list.

**Example output**

```json
{
  "name": "Ana",
  "plan": "pro"
}
```

### Replace text

Find text and replace it with something else.

**Inputs**

- Text to search through (`text`, text, required): The text to search through.
- Text to find (`search`, text, required): The text to find, or a pattern. Every occurrence is replaced.
- Replace with (`replace`, text, required): The text to put in its place.
- Case sensitivity (`case_sensitive`, true/false): Match upper- and lower-case letters exactly (the default). Turn this off to treat them as the same. Default: `true`.
- Find (`search_type`, text): The exact text, or a pattern (a regular expression). With a pattern, $1 in the replacement puts back what its first group in brackets matched, $2 the second. One of: `text` (The exact text), `pattern` (A pattern (regular expression)). Default: `text`.

**Outputs**: The text with every occurrence of the text searched for replaced.

**Example output**

```json
"Order #123 is shipped"
```

### Shorten text

Shorten text so it fits within a set number of characters. By default no ending is added; set an ending like “…” to append one when text is cut. The ending counts toward the limit, so the result never exceeds it.

**Inputs**

- Text (`text`, text, required): The text to shorten.
- Maximum characters (`length`, number, required): Text longer than this is shortened.
- Ending (`ellipsis`, text): Optional ending added when text is shortened, e.g. “…”, counted within the character limit. Leave blank (the default) to shorten without any ending.
- Whole words (`dont_split_words`, true/false): Keep whole words instead of cutting one in the middle. When on, the text is shortened at a word boundary, so the result may come out a little shorter than the limit. Default: `false`.

**Outputs**: The text cut to at most the given number of characters, the ending included, or unchanged if it was short enough.

**Example output**

```json
"The quick brown fox..."
```

### Split text

Split text into a list. Spaces around each piece are left out.

**Inputs**

- Text (`text`, text, required): The text to break into pieces.
- Split at (`delimiter`, text, required): The text to break at, such as a comma or a space.

**Outputs**: The pieces of the text between the separators.

**Example output**

```json
[
  "red",
  "green",
  "blue"
]
```

### Trim whitespace

Remove spaces, tabs, and line breaks from the start and end of text.

**Inputs**

- Text (`text`, text, required): The text to trim.
- Trim from (`mode`, text): Which ends to trim: both ends, only the start, or only the end. Defaults to both ends. One of: `both` (Both ends), `left` (Start), `right` (End). Default: `both`.

**Outputs**: The text with spaces, tabs and line breaks removed from its start, its end, or both.

**Example output**

```json
"Hello world"
```

### Use a fallback if empty

Use a value, or a fallback when it is empty, like a first name or "there" when a contact has none. Zero and false count as values.

**Inputs**

- Value (`value`, text, required): The value to use when it isn't empty.
- Fallback (`default`, text, required): What to use instead when the value is missing, blank, or an empty list.

**Outputs**: The value, or the fallback when the value is empty.

**Example output**

```json
"there"
```

### Validate text

Check whether text is a valid email address, web address, or phone number.

**Inputs**

- Text (`text`, text, required): The text to check, such as an email address, web address or phone number.
- Validate as (`type`, text, required): What kind of value to check for. One of: `email` (Email address), `url` (Web address), `phone` (Phone number). Default: `email`.
- Country (`region`, text): The country of numbers written without a country code. A number that starts with its own, like +44, is checked against that country instead. Defaults to the United States. Default: `US`.

**Outputs**: Whether the text is a valid email address, web address or phone number, whichever was chosen.

**Example output**

```json
true
```
