I am trying to work out a way to personalize emails whereby I utilize the "Full Name" field but parse the data after the first space. I am having issues with my AMPScript for this block:

  SET @FullName = [First Name]
  SET @WhiteSpacePos = IndexOf(@FullName, ' ')
  SET @FirstNamePos = Add(@WhiteSpacePos, 1)
  SET @FirstName = Substring(@FullName, 1, @FirstNamePos)

After doing this, it brings up the values; however, it's 90% perfect. The issue is that the first initial of the second name comes up, e.g., "Sam Smith" comes out "Sam S"

The other issue is that in places where there is just one name. In this case, for example, "Sam" comes out simply just "S".

Any ideas on how to work around these?




substring takes a length argument as the third option, and using the index value from the space gives 1 more length than the first name. Either skip adding 1 to the @WhiteSpacePos value, or use @WhiteSpacePos-1 as the length to substring.

  • Hi Mark, Thanks for writing in. I'm not following you regarding skip adding 1 to the @WhiteSpacePos value. Do you mean to set this line to: SET @FirstNamePos = Add(@WhiteSpacePos, 0) or SET @FirstNamePos = Add(@WhiteSpacePos) Either way, both methods didn't work for me and brought up an error. Regarding @WhiteSpacePos-1 do you mean adding in a 5th line into the script? Thanks, Shmuel – user68909 Jul 18 at 7:06
  • 1
    I mean you can take out the ADD line entirely, it should not be necessary. Try this: %%[ SET @FullName = [First Name] SET @WhiteSpacePos = IndexOf(@FullName, ' ') SET @FirstName = Substring(@FullName, 1, @FirstNamePos) ]%% ` Although that may still catch the whitespace character. If so, put the add part back in, and add -1 – Mark DeHaven Jul 19 at 11:55
  • Thanks Mark! It kind of worked and you gave me the idea to run a VAR AMPScript that uses the INDEXOF query to see if there's a space in the name field. If so, then I used the "fancy" code to parse out only the first name; if not, then I just use the simplified code to use the name. – user68909 Jul 22 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.