> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kiwify.com.br/llms.txt
> Use this file to discover all available pages before exploring further.

# String filters

> String filters for manipulating text in Liquid templates.

## `append`

Concatenates two strings and returns the concatenated value.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "/my/fancy/url" | append: ".html" }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    /my/fancy/url.html
    ```
  </CodeGroup>
</Columns>

`append` can also be used with variables:

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {% assign filename = "/index.html" %}
    {{ "website.com" | append: filename }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    website.com/index.html
    ```
  </CodeGroup>
</Columns>

## `prepend`

Adds the specified string to the beginning of another string.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "apples, oranges, and bananas" | prepend: "Some fruit: " }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    Some fruit: apples, oranges, and bananas
    ```
  </CodeGroup>
</Columns>

`prepend` can also be used with variables:

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {% assign url = "example.com" %}
    {{ "/index.html" | prepend: url }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    example.com/index.html
    ```
  </CodeGroup>
</Columns>

## `capitalize`

Makes the first character of a string capitalized.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "title" | capitalize }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    Title
    ```
  </CodeGroup>
</Columns>

`capitalize` only capitalizes the first character of a string, so later words are not affected:

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "my great title" | capitalize }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    My great title
    ```
  </CodeGroup>
</Columns>

## `upcase`

Makes each character in a string uppercase. It has no effect on strings which are already all uppercase.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "Parker Moore" | upcase }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    PARKER MOORE
    ```
  </CodeGroup>
</Columns>

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "APPLE" | upcase }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    APPLE
    ```
  </CodeGroup>
</Columns>

## `downcase`

Makes each character in a string lowercase. It has no effect on strings which are already all lowercase.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "Parker Moore" | downcase }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    parker moore
    ```
  </CodeGroup>
</Columns>

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "apple" | downcase }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    apple
    ```
  </CodeGroup>
</Columns>

## `strip`

Removes all whitespace (tabs, spaces, and newlines) from both the left and right sides of a string. It does not affect spaces between words.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    BEGIN{{ "          So much room for activities!          " | strip }}END
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    BEGINSo much room for activities!END
    ```
  </CodeGroup>
</Columns>

## `lstrip`

Removes all whitespace (tabs, spaces, and newlines) from the left side of a string. It does not affect spaces between words.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    BEGIN{{ "          So much room for activities!          " | lstrip }}END
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    BEGINSo much room for activities!          END
    ```
  </CodeGroup>
</Columns>

## `rstrip`

Removes all whitespace (tabs, spaces, and newlines) from the right side of a string. It does not affect spaces between words.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    BEGIN{{ "          So much room for activities!          " | rstrip }}END
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    BEGIN          So much room for activities!END
    ```
  </CodeGroup>
</Columns>

## `strip_newlines`

Removes any newline characters (line breaks) from a string.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {% capture string_with_newlines %}
    Hello
    there
    {% endcapture %}

    {{ string_with_newlines | strip_newlines }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    Hellothere
    ```
  </CodeGroup>
</Columns>

## `replace`

Replaces every occurrence of the first argument in a string with the second argument.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    Take your protein pills and put your helmet on
    ```
  </CodeGroup>
</Columns>

## `replace_first`

Replaces only the first occurrence of the first argument in a string with the second argument.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    Take your protein pills and put my helmet on
    ```
  </CodeGroup>
</Columns>

## `replace_last`

Replaces only the last occurrence of the first argument in a string with the second argument.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "Take my protein pills and put my helmet on" | replace_last: "my", "your" }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    Take my protein pills and put your helmet on
    ```
  </CodeGroup>
</Columns>

## `remove`

Removes every occurrence of the specified substring from a string.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "I strained to see the train through the rain" | remove: "rain" }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    I sted to see the t through the
    ```
  </CodeGroup>
</Columns>

## `remove_first`

Removes only the first occurrence of the specified substring from a string.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "I strained to see the train through the rain" | remove_first: "rain" }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    I sted to see the train through the rain
    ```
  </CodeGroup>
</Columns>

## `remove_last`

Removes only the last occurrence of the specified substring from a string.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "I strained to see the train through the rain" | remove_last: "rain" }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    I strained to see the train through the
    ```
  </CodeGroup>
</Columns>

## `truncate`

Shortens a string down to the number of characters passed as an argument. If the specified number of characters is less than the length of the string, an ellipsis (...) is appended to the string and is included in the character count.

### Basic Usage

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "Ground control to Major Tom." | truncate: 20 }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    Ground control to...
    ```
  </CodeGroup>
</Columns>

### Custom ellipsis

`truncate` takes an optional second argument that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (...), but you can specify a different sequence.

The length of the second argument counts against the number of characters specified by the first argument. For example, if you want to truncate a string to exactly 10 characters, and use a 3-character ellipsis, use **13** for the first argument of `truncate`, since the ellipsis counts as 3 characters.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "Ground control to Major Tom." | truncate: 25, ", and so on" }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    Ground control, and so on
    ```
  </CodeGroup>
</Columns>

### No ellipsis

You can truncate to the exact number of characters specified by the first argument and avoid showing trailing characters by passing a blank string as the second argument:

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "Ground control to Major Tom." | truncate: 20, "" }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    Ground control to Ma
    ```
  </CodeGroup>
</Columns>

## `split`

Divides a string into an array using the argument as a separator. `split` is commonly used to convert comma-separated items from a string to an array.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {% assign beatles = "John, Paul, George, Ringo" | split: ", " %}

    {% for member in beatles %}
      {{ member }}
    {% endfor %}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    John

      Paul

      George

      Ringo
    ```
  </CodeGroup>
</Columns>

## `truncatewords`

Shortens a string down to the number of words passed as an argument. If the specified number of words is less than the number of words in the string, an ellipsis (...) is appended to the string.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "Ground control to Major Tom." | truncatewords: 3 }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    Ground control to...
    ```
  </CodeGroup>
</Columns>

#### Custom ellipsis

`truncatewords` takes an optional second argument that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (...), but you can specify a different sequence.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "Ground control to Major Tom." | truncatewords: 3, "--" }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    Ground control to--
    ```
  </CodeGroup>
</Columns>

#### No ellipsis

You can avoid showing trailing characters by passing a blank string as the second argument:

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "Ground control to Major Tom." | truncatewords: 3, "" }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    Ground control to
    ```
  </CodeGroup>
</Columns>

## `normalize_whitespace`

Replace any occurrence of whitespace with a single space.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "a \n b" | normalize_whitespace }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    a b
    ```
  </CodeGroup>
</Columns>

## `number_of_words`

Count the number of words in some text. This filter takes an optional argument to control the handling of Chinese-Japanese-Korean (CJK) characters in the input string:

* Passing `'cjk'` as the argument will count every CJK character detected as one word irrespective of being separated by whitespace.
* Passing `'auto'` (auto-detect) works similar to `'cjk'` but is more performant if the filter is used on a variable string that may or may not contain CJK chars.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "Hello world!" | number_of_words }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    2
    ```
  </CodeGroup>
</Columns>

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "你好hello世界world" | number_of_words }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    1
    ```
  </CodeGroup>
</Columns>

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "你好hello世界world" | number_of_words: "cjk" }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    6
    ```
  </CodeGroup>
</Columns>

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "你好hello世界world" | number_of_words: "auto" }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    6
    ```
  </CodeGroup>
</Columns>

## `array_to_sentence_string`

Convert an array into a sentence. Useful for listing tags. Optional argument for connector.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "foo,bar,baz" | split: "," | array_to_sentence_string }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    foo, bar, and baz
    ```
  </CodeGroup>
</Columns>

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "foo,bar,baz" | split: "," | array_to_sentence_string: "or" }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    foo, bar, or baz
    ```
  </CodeGroup>
</Columns>
