Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
Locked
0

How to remove the first characters of a liquid string

Contributor ,
Jul 07, 2016 Jul 07, 2016

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

TOPICS
Newbie Corner
8.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jul 09, 2016 Jul 09, 2016

Assign a sliced value and you can have array data which you can output.

Translate
LEGEND ,
Jul 07, 2016 Jul 07, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 07, 2016 Jul 07, 2016

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 07, 2016 Jul 07, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 08, 2016 Jul 08, 2016

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

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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 09, 2016 Jul 09, 2016

Assign a sliced value and you can have array data which you can output.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 09, 2016 Jul 09, 2016
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines