Adding possessive apostrophe to names – AMPscript

So we have some personalization in an email where we want to greet the recipient using their first name. In the example the first name was a pet name and the email was alerting the recipient that it was time for their pet’s shots, checkup, etc.

It’s time for Sparky’s checkup.

The works fine, but if the pet name ends in “s”, we want to just add the apostrophe and not the apostrophe and the “s”.

Let’s say your dog’s name is “Spots”.

So, we want to check and see if the pet name ends in “s”.

First I’ll make sure the pet name is in the case I want it in (upper, lower, proper).

Set @PET_NAME = ProperCase(@PET_NAME)

Then I’ll get the length of the name.


Now, let’s check to see if “s” is the last character. If it is, we’ll set a variable to hold just the apostrophe (‘). If the last character is not an “s”, we’ll set the variable to apostrophe + “s” (‘s).

Set @PATIENT_NAME_Apostrophe = "'"
Set @PATIENT_NAME_Apostrophe = "'s"

Substring(S1, I1, I2)
Returns the portion of the specified string starting with the specified character position and no longer than the specified length. If the specified character position is greater than the length of the specified string, an empty string is returned.


S1 The string from which to return a portion
I1 The character position at which to begin the substring
I2 Maximum length of the substring



System returns:bc

Thank you for reading!