SOLVED

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

Go to solution
Jules1
Level 1

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?

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

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

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

View solution in original post

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

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

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

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

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 - Community Moderator

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

Doesn't sound like you tested the code?
Jules1
Level 1

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

Sorry will do shortly, we're having heaps of issues with Marketo at the moment

SanfordWhiteman
Level 10 - Community Moderator

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

@Jules1 please return to your thread to check replies.