Copy link to clipboard
Copied
I would like to remove the first three characters of a liquid string. The question is how.
If I use the following liquid markup when I know what the first characters are
{{this.{["Estate Status"] | strip_html | remove_first: '11.'}}
it will remove the characters 11.
But if I don't know what the first characters are, what markup do I have to use to get "rid" of the first three characters?
I've tried "split" and "slice" but you always have to know what characters to split or slice.
Thanks for any help.
Kind regards,
Carla
Assign a sliced value and you can have array data which you can output.
Copy link to clipboard
Copied
Hi Carla,
Are you sure remove_first works?
That is not a supported filter in BC:
Filters | Business Catalyst Support
You have replace and replace_first and remove.
If you use the reference documentation you can see you have slice. Which will do the trick for you.
Copy link to clipboard
Copied
Hi Liam,
Perhaps I discovered something new in BC liquid but the code below actually worked.
<p class="property-details__answer"> {{this.{["Estate Status"] | strip_html | remove_first: '11.'}}</p>
But what I'm trying to figure out is removing the first characters if I don't know what they are. I only know that those first characters have to be removed.
In my web app field the client can choose one option of a list which starts with a number 01. to 15. Of those numbers I want to get rid off.
If I would use replace and replace_first I would have to know the value's output wouldn't I?
Copy link to clipboard
Copied
This is not even on the shopify documentation and I tested this and can confirm it defiantly does not work.
Not sure what you have in your code or what you think but the above if I implement it does not work.
Did you read my post or look at the documentation? You need to be using slice.
Copy link to clipboard
Copied
Hi Liam,
I did read your post. Thanks for that. But I can't figure out how to use "slice". When I used slice the first characters were "sliced" but I couldn't manage to display the remaining characters.
As I tried to explain only the first 3 characters have to be removed/sliced the remaining characters have to be displayed. The remaining characters/sentence have/has a
variable length
e.g
99. some sentence with several characters with variable length
The "99." has to be removed
Only "some sentence with several characters with variable length" has to be shown.
Perhaps you could help me out on this how the code should be.
Btw. I've found this on the Shopify help pages:
https://help.shopify.com/themes/liquid/filters/string-filters#remove_first
Removes only the first occurrence of a substring from a string.
Input
{{ "Hello, world. Goodbye, world." | remove_first: "world" }}
Output
Hello, . Goodbye, world.
Copy link to clipboard
Copied
Assign a sliced value and you can have array data which you can output.
Copy link to clipboard
Copied
Thanks Liam. You have put me on the right track.
input:
99. some sentence with several characters with variable length
The code is as follows:
<p class="property-details__answer"> {{this.{["Estate Status"] | strip_html | split: '.'| last'}}</p>
Output:
some sentence with several characters with variable length