Remove the last character of a string with Liquid

Reading time: 1 minute

Sometimes, when manipulating a string or receiving a string from some variable or function, you want to get rid of the string's last character. There might be a period there, or a slash, or some other remnant of a previous operation. In any case, you want to get rid of that last character.

So how do you do this in Liquid?

You first get the length of the string, then use the slice filter to split it into two parts, where the second part is the last character and the first part is the rest of the string. Then you assign that first part to a variable.

Here's the code:

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.