Counting the number of specific characters in a string in velocity script for email | Community
Skip to main content
Level 2
June 6, 2023
Solved

Counting the number of specific characters in a string in velocity script for email

  • June 6, 2023
  • 2 replies
  • 2250 views

I'm building a html email and in a token I have a string field which has a list of up to 7 phone numbers in it, each phone number separated by a comma, e.g:

01234567, 01234567, 01234567, 01234567

I need to be able to replace the last comma in the string with ' and' instead of the comma. What would be the best way of doing it?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

Your subject line seems at odds with your question — this doesn’t have to do with counting, right?

 

It sounds like you want to split the string into an array and then display the array in a “friendly” way.

${display.list($lead.someStringField.split("\s*,\s*"))}

2 replies

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
June 6, 2023

Your subject line seems at odds with your question — this doesn’t have to do with counting, right?

 

It sounds like you want to split the string into an array and then display the array in a “friendly” way.

${display.list($lead.someStringField.split("\s*,\s*"))}
Jules1Author
Level 2
June 6, 2023

Sorry I was having issues logging in to Marketo... yep that would work, then how wold I add the 'and' before the last list item, would that involve counting them?

SanfordWhiteman
Level 10
June 7, 2023
Doesn't sound like you tested the code?
SanfordWhiteman
Level 10
June 6, 2023

@jules1 please return to your thread to check replies.