Use Substring to get Someone’s Initials

The most used method of personalizing content is to use the recipient’s name.

There are so many places where you can plug in someone’s name to make the email feel more like a 1:1 communication. We can use the name in the subject line, or to open the email with a personal touch. Adding the name to the copy is another great opportunity.

With all of the privacy laws that have gone into effect, such as GDPR or CCPA, most companies have established rules around what Personal Identifiable Information (PII) you are able to use. Using a someone’s full name is usally against company policy. But there are times where only using someone’s first name feels too informal.

I recently built a campaign where we were asking people to add their name to a petition. The marketing team really wanted to display the full name, but our InfoSec team said no. After lots of back and forth, it was decided that we could use their last initial but not their full last name.

There is no field on the subscriber for last initial. We only had the full last name. So we used AMPscript to pull out the first character in the last name – thereby giving us their initial.

The AMPscript function we used is SUBSTRING(). This function’s job is to return a piece of a string. You can tell it where to start in the string, and how many characters it should return. So to get the initial, we told the function to start at the beginning and to give us 1 character. Before I give you the code for that though, let’s look at how this function works.




fullstring = This is the string you have that you are looking to pull a chink from. It can be passed as a @variable or in “string format”

startingposition= This is the character you want to start with. It can be passed as a @variable or as a number. For example, if you want to start on the 3rd letter, you put “3” as your starting position.

numofcharacters= This is the number of characters you want it to return. It can be passed as a @variable or as a number. For example, if we are grabbing an initial, we only need 1 character.

Simple Examples:

Get 1 character and start at the beginning of the fullstring:
substring(“abcdefghijklmnopqrstuvwxyz”,1,1) → a

Get 2 characters and start at the 2nd character of the fullstring:
substring(“abcdefghijklmnopqrstuvwxyz”,2,2) → bc

Get 7 characters and start at the 12th character of the fullstring:
substring(“abcdefghijklmnopqrstuvwxyz”,12,7) → lmnopqr

Below is an example where I am pulling the initial and creating a string that has both the first name and last initial. I used it to populate a dynamic image, but there are tons of uses.

VAR @FirstName, @LastName, @LastInitial, @NameString
set @FirstName = [FirstName]
set @LastName = [LastName]
set @LastInitial = substring(@LastName,1,1)
set @FirstName= propercase(@FirstName)
set @LastInitial = propercase(@LastInitial)
set @NameString= concat(@FirstName," ",@LastInitial)

The code example above is doing the following:

  1. Declaring the variables
  2. Setting the @FirstName variable from the data
  3. Setting the @LastName variable from the data
  4. Using substring to take 1 character from the string starting on the 1st character
  5. Capitalizing @FirstName, just to be safe (Learn more about propercase)
  6. Capitalizing @Last Initial, just to be safe
  7. Using Concat to string the first and last initial into one string


Salesforce Developer – Substring()

AMPscript Guide – Substring()

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.