Get last item of a list while doing personalization in AJO campaigns | Adobe Higher Education
Skip to main content
arpan-garg
Community Advisor
Community Advisor
January 31, 2024
Beantwortet

Get last item of a list while doing personalization in AJO campaigns

  • January 31, 2024
  • 1 Antwort
  • 861 Ansichten

Hi ,

 

I am trying to split a string and get the last item from the list. For this, i am not sure what helper function to use.

I have a string lets say sampleString with value abc-12345.

For splitting i am using the split function {%= split(sampleString,"-") %} and this is giving me the result List(abc, 12345) which is expected. Now from this list i want to fetch the last element .

On the documents it says head can be used to fetch the first element but can't find anything to fetch the last element of the list.

 

Thanks,

Arpan

Dieses Thema wurde für Antworten geschlossen.
Beste Antwort von Mohan_Dugganab

Following expression can be used to get the last porting of the string after "-", See if this meets your requirement


{% let idx = lastIndexOf("hello-world-test-string","-" ) + 1 %}
{%= substr("hello-world-test-string", idx, length("hello-world-test-string") ) %}

1 Antwort

Mohan_Dugganab
Adobe Employee
Adobe Employee
February 1, 2024

Following expression can be used to get the last porting of the string after "-", See if this meets your requirement


{% let idx = lastIndexOf("hello-world-test-string","-" ) + 1 %}
{%= substr("hello-world-test-string", idx, length("hello-world-test-string") ) %}

arpan-garg
Community Advisor
Community Advisor
February 2, 2024

Hi @mohan_dugganab  - Thanks for this, i was aware of the string functions and this can definitely be used. I was just wondering if there is a more cleaner function to achieve this. Like we have "head" to fetch the first element of the list.

Mohan_Dugganab
Adobe Employee
Adobe Employee
February 2, 2024