Overview

As we dive into more complex AMPscript logic we may come across situations where we need to manipulate string values to achieve different things. We can do this by using the following functions listed below:

  • Lowercase(1)
  • Uppercase(1)
  • Propercase(1)
  • Trim(1)
  • Empty(1)

Examples

Lowercase Function
An example of when we might use this function is if a client wants us to render email copy in all lowercase letters. For example, let’s say that the client’s data contains values in in all uppercase letters. We can use the Lowercase function to convert the client’s data from uppercase to lowercase without having to manually update data in the data extension.

<!-- Example Code -->
%%[
/*
* Lowercase logic
* Converts the uppercase string to lowercase.
*/
VAR @name
SET @name = Lowercase("JOHN DOE")
]%%
%%=v(@name)=%%
<!-- Example Output -->
john doe
View this gist on GitHub

Uppercase Function
An example of when we might use this function is if a client wants us to render email copy in all uppercase letters. For example, let’s say that the client’s data contains values in all lowercase letters. We can use the Uppercase function to convert the client’s data from lowercase to uppercase without having to manually update data in the data extension.

<!-- Example Code -->
%%[
/*
* Uppercase logic
* Converts the lowercase string to uppercase.
*/
VAR @name
SET @name = Uppercase("john doe")
]%%
%%=v(@name)=%%
<!-- Example Output -->
JOHN DOE
View this gist on GitHub

Propercase Function
An example of when we might use this function is if a client wants us to render email copy using proper case formatting. For example, let’s say that the client’s data contains values in all uppercase letters. We can use the ProperCase function to convert the client’s data from uppercase to proper case without having to manually update data in the data extension.

<!-- Example Code -->
%%[
/*
* Propercase logic
* Converts any case to propercase.
*/
VAR @name
SET @name = Uppercase("jOhN dOe")
]%%
%%=v(@name)=%%
<!-- Example Output -->
John Doe
View this gist on GitHub

Trim Function
There may be instances where the client provides data with undesired spaces. An example might be if the client has a field in the sendable data extension called fname. The client accidently uses “  John  ” in that field rather than “John”. In order to clean this up prior to using it in the email we use the Trim function to strip out unwanted spaces before and after the data value.

<!-- Example Code -->
%%[
/*
* Trim Logic
* Removes the white space before and after the text.
*/
VAR @value1, @value2
SET @value1 = " Hello World "
SET @value2 = Trim(@value1)
]%%
%%=v(@value2)=%%
<!-- Example Output -->
Hello World
View this gist on GitHub

Empty Function
This function is used often to evaluate whether a variable is empty or not. You’ll notice that this function is combined with other functions to evaluate and personalize content. In this example, we check to see if @name is empty or not. If so, then set the @name variable to “Valued Customer” to use as a fallback.

<!-- Example Code -->
%%[
/*
* Empty logic
* If subscriber FirstName exists then set the name var to FirstName.
* If subscriber FirstName does not exist, then set the name var to Valued Customer.
*/
VAR @name
SET @name = ""
IF NOT EMPTY(@name) THEN
SET @name = ProperCase(@name)
ELSE
SET @name = "Valued Customer"
ENDIF
]%%
%%=v(@name)=%%
<!-- Example Output -->
Valued Customer
View this gist on GitHub

Gallery