Suppose you want to output a day of the month with a proper suffix (e.g. 1st, 13th). There aren’t any formatting functions in AMPScript to do it, but you can do it with a set of if-statements:
Once you’re satisfied that it works, you can simply remove the for-loop and un-comment the set @day = Format(Now(),"dd")) line
Say you need to find the lowest of three numbers in an email — numbers you’ve retrieved from a Data Extension. Here’s one way to do it in AMPScript with a set of inline-if statements:
Do you know about the MicrositeURL() AMPScript function? It’s relatively new. It sure is handy if you’re building custom preference centers in Enterprise 2.0 business units.
The idea is that you can encrypt custom parameters in your email links to Microsite pages and then retrieve the unencrypted values with an AMPScript function. Once you have the business unit MID in the microsite page, you can use it to ensure your API calls are for the correct business unit.
In your email you would have this code:
In the case where the the subscriberMID is not set, default to the parent business unit’s MID, which is accessible from the memberid personalization string.
For further reading:
Did you know you can use regular expressions in AMPScript?
Here are some RegExMatch() snippets that I’ve used:
@s = input string
@p = pattern
@m = match
@o = output
Strip leading zeroes from a string
Check for all digits, no match
Check for all digits, match
Replace parenthetical text with space
input: whee (whatever it is) whoop
match: (whatever it is)
output: whee whoop
For further reading
RegEx pattern reference
RegEx options reference