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.
Set @PET_NAME_LENGTH = Length(@PET_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).
IF Substring(@PATIENT_NAME,@PATIENT_NAME_LENGTH,1) == "s" THEN Set @PATIENT_NAME_Apostrophe = "'" ELSE Set @PATIENT_NAME_Apostrophe = "'s" ENDIF
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