I am very new to AMPscript (read: I've never used it), but I think it may be able to help me solve a problem I am having. I am using an integration with salesforce CRM and want to set an automated email to send weekly to people who are signed up for a program the following week. I want to include the name of the program that they are signed up for in the email as a personalization. I can set this field to be automatically imported into the data extension that the automation will use, no problem. The problem is that the CRM field that I use has a string of 3 characters at the beginning of the field and a string of 5 characters at the end of the field that I DO NOT want to include in the email, and the program names in between these two ends can vary in length from week to week.

For instance, one week's programs are in the CRM as "DC:Build it, Destroy it (3-6)" and the following week's are in the CRM as "DC:Amusement Park Physics (3-6)". I want to always remove the "DC:" from the beginning of this field and the "(3-6)" from the end of this field.

It seems like the Substring function would help me, but the fact that the lengths of the program names vary seems like maybe not? Does anyone have code that can perform this task for me of always removing the first 3 characters and final 5 characters from this field?

1 Answer 1


Substring is the right function. You would do

Set @attribute = AttributeValue('yourattribute')
Set @finalstr = Substring(@attribute, 4, Subtract(length(@attribute), 5))



And that should output what you need regardless of string size.

  • Thank you so much! This is so close to working, but something isn't quite right. When the Attribute is "DC: Build it, Destroy it (3-6)", for some reason with your code it is showing up as "Build it, Destroy it (3-" I adjusted the 5 to 8 in your code until it got rid of all of the parenthetical at the end but I don't understand why it needed to be 8 because I don't see 8 characters at the end. I'm worried that this won't work when there is a different length in the middle...
    – M. Roche
    Jun 8, 2017 at 17:00
  • Check to see if you have any spaces or other 'hidden' characters at the end of your string. Substring will include all chars in its calculation. Jun 8, 2017 at 17:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .