# String

String filters modify [strings](/docs/theme/references/liquid/basics/liquid-types#string).

## append

`string | append: string`

returns  [string](../basics/liquid-types#string)

Adds a given string to the end of a string.

**Code**

```liquid
{{ shop.url | append: product.url }}
```

**Data**

```json
{
  "product": {
    "url": "/products/reverse-short-sleeve-tee"
  }
}
```

**Output**

```html
https://shop.myshoplaza.com/products/reverse-short-sleeve-tee
```

## camelcase

`string | camelcase`

returns  [string](../basics/liquid-types#string)

Converts a string to CamelCase.

**Code**

```liquid
{{ 'camel-case' | camelcase }}
```

**Output**

```html
CamelCase
```

## capitalize

`string | capitalize`

returns  [string](../basics/liquid-types#string)

Capitalizes every word in a string.

**Code**

```liquid
{{ 'this sentence should start with a capitalized word.' | capitalize }}
```

**Output**

```html
This Sentence Should Start With A Capitalized Word.
```

## downcase

`string | downcase`

returns  [string](../basics/liquid-types#string)

Converts a string to all lowercase characters.

**Code**

```liquid
{{ product.title | downcase }}
```

**Data**

```json
{
  "product": {
    "title": "Ace Cashmere Beanie"
  }
}
```

**Output**

```html
ace cashmere beanie
```

## escape

`string | escape`

returns  [string](../basics/liquid-types#string)

Escapes special characters in HTML, such as `<>`, `'`, `"`, and `&`, and converts characters into escape sequences. The filter doesn't affect characters within the string that don’t have a corresponding escape sequence.

**Code**

```liquid
{{ '<p>Text to be escaped.</p>' | escape }}
```

**Output**

```html
&lt;p&gt;Text to be escaped.&lt;/p&gt;
```

## escape\_once

`string | escape_once`

returns  [string](../basics/liquid-types#string)

Escapes a string without changing characters that have already been escaped.

**Code**

```liquid
{% assign escaped_text = '<p>Text to be escaped.</p>' | escape %}

{{ escaped_text }}
{{ escaped_text | escape_once }}
```

**Output**

```html
&lt;p&gt;Text to be escaped.&lt;/p&gt;
&lt;p&gt;Text to be escaped.&lt;/p&gt;
```

## handleize

`string | handleize`

returns  [string](../basics/liquid-types#string)

Converts a string into a [handle](/docs/theme/references/liquid/basics/handles).

**note**

The `handleize` filter has an alias of `handle`.

**Code**

```liquid
{{ product.title | handleize }}
{{ product.title | handle }}
```

**Data**

```json
{
  "product": {
    "title": "Ace Cashmere Beanie"
  }
}
```

**Output**

```html
ace-cashmere-beanie
ace-cashmere-beanie
```

## hmac\_sha1

`string | hmac_sha1: string`

returns  [string](../basics/liquid-types#string)

Converts a string into an SHA-1 hash using a hash message authentication code (HMAC).

The secret key for the message is supplied as a parameter to the filter.

**Code**

```liquid
{{ 'Ace' | hmac_sha1: 'Salty' }}
```

**Output**

```html
5da24ef75f6a8fc7d28c0fcc7236244d29a4511d
```

## hmac\_sha256

`string | hmac_sha256: string`

returns  [string](../basics/liquid-types#string)

Converts a string into an SHA-256 hash using a hash message authentication code (HMAC).

The secret key for the message is supplied as a parameter to the filter.

**Code**

```liquid
{{ 'Ace' | hmac_sha256: 'Salty' }}
```

**Output**

```html
8f688efb30c4e26bed3e14923030f9276e463e7933c88fc18c0ff0c934185418
```

## lstrip

`string | lstrip`

returns  [string](../basics/liquid-types#string)

Strips all whitespace from the left of a string.

**Code**

```liquid
{% assign text = '  Some fruits create whitespace.    ' %}
"{{ text }}"
"{{ text | lstrip }}"
```

**Output**

```html
" Some fruits create whitespace. "
"Some fruits create whitespace. "
```

## md5

`string | md5`

returns  [string](../basics/liquid-types#string)

Converts a string into an MD5 hash.

**Code**

```liquid
{{ '' | md5 }}
```

**Output**

```html
d41d8cd98f00b204e9800998ecf8427e
```

## newline\_to\_br

`string | newline_to_br`

returns  [string](../basics/liquid-types#string)

Converts newlines (`\n`) in a string to HTML line breaks (`<br>`).

**Code**

```liquid
{% capture description %}
  <h3>Sound inspired</h3>
  <div>Get inspired with Solo Pro wireless headphones.</div>
{% endcapture %}

{{ description | newline_to_br }}
```

**Output**

```html
<br>
<h3>Sound inspired</h3>
<br>
<div>Get inspired with Solo Pro wireless headphones.</div>
<br>
```

## pluralize

`number | pluralize: string, string`

returns  [string](../basics/liquid-types#string)

Outputs the singular or plural version of a string based on a given number.

**Code**

```liquid
{% assign item_count = cart.cart %}

Cart item count: {{ item_count }} {{ item_count | pluralize: 'item', 'items' }}
```

**Data**

```json
{
  "cart": {
    "item_count": 2
  }
}
```

**Output**

```html
Cart item count: 2 items
```

## prepend

`string | prepend: string`

returns  [string](../basics/liquid-types#string)

Adds a given string to the beginning of a string.

**Code**

```liquid
{{ product.url | prepend: shop.url }}
```

**Data**

```json
{
  "product": {
    "url": "/products/reverse-short-sleeve-tee"
  }
}
```

**Output**

```html
https://shop.myshoplaza.com/products/reverse-short-sleeve-tee
```

## remove

`string | remove: string`

returns  [string](../basics/liquid-types#string)

Removes any instance of a substring inside a string.

**Code**

```liquid
{{ "I can't do it!" | remove: "'t" }}
```

**Output**

```html
I can do it!
```

## remove\_first

`string | remove_first: string`

returns  [string](../basics/liquid-types#string)

Removes the first instance of a substring inside a string.

**Code**

```liquid
{{ "I don't know why, but I don't know how to do it." | remove_first: "don't" }}
```

**Output**

```html
I know why, but I don't know how to do it.
```

## replace

`string | replace: string, string`

returns  [string](../basics/liquid-types#string)

Replaces any instance of a substring inside a string with a given string.

**Code**

```liquid
{{ product.handle | replace: '-', ' ' }}
```

**Data**

```json
{
  "product": {
    "handle": "ace-cashmere-beanie"
  }
}
```

**Output**

```html
ace cashmere beanie
```

## replace\_first

`string | replace_first: string, string`

returns  [string](../basics/liquid-types#string)

Replaces the first instance of a substring inside a string with a given string.

**Code**

```liquid
{{ product.handle | replace_first: '-', ' ' }}
```

**Data**

```json
{
  "product": {
    "handle": "ace-cashmere-beanie"
  }
}
```

**Output**

```html
ace cashmere-beanie
```

## rstrip

`string | rstrip`

returns  [string](../basics/liquid-types#string)

Strips all whitespace from the right of a string.

**Code**

```liquid
{% assign text = '  Some fruits create whitespace.    ' %}
"{{ text }}"
"{{ text | rstrip }}"
```

**Output**

```html
" Some fruits create whitespace. "
" Some fruits create whitespace."
```

## sha1

`string | sha1`

returns  [string](../basics/liquid-types#string)

Converts a string into an SHA-1 hash.

**Code**

```liquid
{{ 'Ace' | sha1 }}
```

**Output**

```html
fc2b5a9cb80ab0a1526f4fbc887646dd245632c2
```

## sha256

`string | sha256`

returns  [string](../basics/liquid-types#string)

Converts a string into an SHA-256 hash.

**Code**

```liquid
{{ 'Ace' | sha256 }}
```

**Output**

```html
a467da82da540f56097b7224d81612bfa212e26efbf0709606144fee0b82a631
```

## slice

`string | slice`

returns  [string](../basics/liquid-types#string)

Returns a substring or series of array items, starting at a given 0-based index.

By default, the substring has a length of one character, and the array series has one array item. However, you can provide a second parameter to specify the number of characters or array items.

**Code**

```liquid
{{ collection.title | slice: 0 }}
{{ collection.title | slice: 0, 3 }}
{{ collection.tags | slice: 1, 2 | join: ', ' }}
```

**Data**

```json
{
  "collection": {
    "tags": [
      "Burning",
      "fresh",
      "music",
      "plant",
      "Salty"
    ],
    "title": "All products"
  }
}
```

**Output**

```html
All products
All
fresh, music
```

### Negative index

You can supply a negative index which will count from the end of the string.

**Code**

```liquid
{{ title | slice: -8, 8 }}
```

**Data**

```json
{
  "collection": {
    "title": "All products"
  }
}
```

**Output**

```html
products
```

## split

`string | split: string`

returns  [string](../basics/liquid-types#string)

Splits a string into an array of substrings based on a given separator.

**Code**

```liquid
{% assign title_words = product.handle | split: '-' %}

{% for word in title_words %}
  {{ word }}
{% endfor %}
```

**Data**

```json
{
  "product": {
    "handle": "ace-cashmere-beanie"
  }
}
```

**Output**

```html
ace
cashmere
beanie
```

## strip

`string | strip`

returns  [string](../basics/liquid-types#string)

Strips all whitespace from the left and right of a string.

**Code**

```liquid
{% assign text = '  Some fruits create whitespace.    ' %}
"{{ text }}"
"{{ text | strip }}"
```

**Output**

```html
" Some fruits create whitespace. "
"Some fruits create whitespace."
```

## strip\_html

`string | strip_html`

returns  [string](../basics/liquid-types#string)

Strips all HTML tags from a string.

**Code**

```liquid
<!-- With HTML -->
{{ product.description }}

<!-- HTML stripped -->
{{ product.description | strip_html }}
```

**Data**

```json
{
  "product": {
    "description": "<h3>Sound inspired</h3>\n<div>Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode.</div>"
  }
}
```

**Output**

```html
<!-- With HTML -->
<h3>Sound inspired</h3>
<div>Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode.</div>

<!-- HTML stripped -->
Sound inspired
Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode.
```

## strip\_newlines

`string | strip_newlines`

returns  [string](../basics/liquid-types#string)

Strips all newline characters (line breaks) from a string.

**Code**

```liquid
<!-- With newlines -->
{{ product.description }}

<!-- Newlines stripped -->
{{ product.description | strip_newlines }}
```

**Data**

```json
{
  "product": {
    "description": "<h3>Sound inspired</h3>\n<div>Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode.</div>"
  }
}
```

**Output**

```html
<!-- With newlines -->
<h3>Sound inspired</h3>
<div>Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode.</div>

<!-- Newlines stripped -->
<h3>Sound inspired</h3><div>Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode.</div>
```

## truncate

`string | truncate: number`

returns  [string](../basics/liquid-types#string)

Truncates a string down to a given number of characters.

If the specified number of characters is less than the length of the string, then an ellipsis (`...`) is appended to the truncated string. The ellipsis is included in the character count of the truncated string.

**Code**

```liquid
{{ product.title | truncate: 10 }}
{{ product.title | truncate: 20 }}
```

**Data**

```json
{
  "product": {
    "title": "Ace Cashmere Beanie"
  }
}
```

**Output**

```html
Ace Cas...
Ace Cashmere Beanie
```

### Specify a custom ellipsis

`string | truncate: number, string`

You can provide a second parameter to specify a custom ellipsis. If you don't want an ellipsis, then you can supply an empty string.

**Code**

```liquid
{{ product.title | truncate: 10, '' }}
{{ product.title | truncate: 10, '···' }}
```

**Data**

```json
{
  "product": {
    "title": "Ace Cashmere Beanie"
  }
}
```

**Output**

```html
Ace Cashme
Ace ···
```

## truncatebytes

`string | truncatebytes: number`

returns  [string](../basics/liquid-types#string)

Truncates a string down to a given number of bytes.

If the specified number of characters is less than the length of the string, then an ellipsis (`...`) is appended to the truncated string. The ellipsis is included in the character count of the truncated string.

**Code**

```liquid
{{ product.description | truncatebytes: 50 }}
```

**Data**

```json
{
  "product": {
    "description": "Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode. Beats’ Pure ANC gives you the space to create with fully immersive sound, while Transparency mode helps you stay aware of your surroundings. Every detail of Solo Pro has been carefully considered, right down to the intuitive way the headphones turn on and off via folding. The ergonomic design delivers exceptional comfort for extended wear and sleek style. And with up to 22 hours of battery life, you can keep the music going no matter where your day takes you."
  }
}
```

**Output**

```html
Get inspired with Solo Pro wireless headphones....
```

### Specify a custom ellipsis

`string | truncatebytes: number, string`

You can provide a second parameter to specify a custom ellipsis. If you don't want an ellipsis, then you can supply an empty string.

**Code**

```liquid
{{ product.description | truncatebytes: 50, '' }}
{{ product.description | truncatebytes: 50, '···' }}
```

**Data**

```json
{
  "product": {
    "description": "Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode. Beats’ Pure ANC gives you the space to create with fully immersive sound, while Transparency mode helps you stay aware of your surroundings. Every detail of Solo Pro has been carefully considered, right down to the intuitive way the headphones turn on and off via folding. The ergonomic design delivers exceptional comfort for extended wear and sleek style. And with up to 22 hours of battery life, you can keep the music going no matter where your day takes you."
  }
}
```

**Output**

```html
Get inspired with Solo Pro wireless headphones. To
Get inspired with Solo Pro wireless headphon···
```

## truncatewords

`string | truncatewords: number`

returns  [string](../basics/liquid-types#string)

Truncates a string down to a given number of words.

If the specified number of words is less than the number of words in the string, then an ellipsis (`...`) is appended to the truncated string.

**Code**

```liquid
{{ product.description | truncatewords: 10 }}
```

**Data**

```json
{
  "product": {
    "description": "Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode. Beats’ Pure ANC gives you the space to create with fully immersive sound, while Transparency mode helps you stay aware of your surroundings. Every detail of Solo Pro has been carefully considered, right down to the intuitive way the headphones turn on and off via folding. The ergonomic design delivers exceptional comfort for extended wear and sleek style. And with up to 22 hours of battery life, you can keep the music going no matter where your day takes you."
  }
}
```

**Output**

```html
Get inspired with Solo Pro wireless headphones. To deliver sound...
```

### Specify a custom ellipsis

`string | truncatewords: number, string`

returns  [string](../basics/liquid-types#string)

You can provide a second parameter to specify a custom ellipsis. If you don't want an ellipsis, then you can supply an empty string.

**Code**

```liquid
{{ product.description | truncatewords: 10, '' }}
{{ product.description | truncatewords: 10, '---' }}
```

**Data**

```json
{
  "product": {
    "description": "Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode. Beats’ Pure ANC gives you the space to create with fully immersive sound, while Transparency mode helps you stay aware of your surroundings. Every detail of Solo Pro has been carefully considered, right down to the intuitive way the headphones turn on and off via folding. The ergonomic design delivers exceptional comfort for extended wear and sleek style. And with up to 22 hours of battery life, you can keep the music going no matter where your day takes you."
  }
}
```

**Output**

```html
Get inspired with Solo Pro wireless headphones. To deliver sound
Get inspired with Solo Pro wireless headphones. To deliver sound---
```

## upcase

`string | upcase`

returns  [string](../basics/liquid-types#string)

Converts a string to all uppercase characters.

**Code**

```liquid
{{ product.title | upcase }}
```

**Data**

```json
{
  "product": {
    "title": "Ace Cashmere Beanie"
  }
}
```

**Output**

```html
ACE CASHMERE BEANIE
```

## url\_decode

`string | url_decode`

returns  [string](../basics/liquid-types#string)

Decodes any [percent-encoded](https://developer.mozilla.org/en-US/docs/Glossary/percent-encoding) characters in a string.

**Code**

```liquid
{{ 'https%3A%2F%2Fwww.shoplazza.com%2F' | url_decode }}
```

**Output**

```html
https://www.shoplazza.com/
```

## url\_encode

`string | url_encode`

returns  [string](../basics/liquid-types#string)

Converts any URL-unsafe characters in a string to the [percent-encoded](https://developer.mozilla.org/en-US/docs/Glossary/percent-encoding) equivalent.

**note**

Spaces are converted to a `+` character, instead of a percent-encoded character.

**Code**

```liquid
{{ 'https://www.shoplazza.com/' | url_encode }}
```

**Output**

```html
https%3A%2F%2Fwww.shoplazza.com%2F
```
