Skip to main content
Level 2
Jun 6, 2023 8:11 AM UTC
Solved

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

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.
SanfordWhiteman
SanfordWhitemanAccepted solution
User Group Leader
Jun 6, 2023 8:22 AM UTC

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*"))}

5 replies

SanfordWhiteman
User Group Leader
SanfordWhitemanUser Group LeaderAccepted solution
User Group Leader
Jun 6, 2023 8:22 AM UTC

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*"))}
Translate
Jules1Author
Level 2
Jun 6, 2023 11:31 PM UTC

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?

Translate
SanfordWhiteman
User Group Leader
User Group Leader
Jun 7, 2023 12:08 AM UTC
Doesn't sound like you tested the code?
Translate
SanfordWhiteman
User Group Leader
User Group Leader
Jun 6, 2023 5:32 PM UTC

@jules1 please return to your thread to check replies.

Translate