How do I get the username or domain from an email address?
The obvious use of lists in ColdFusion is to work with a lists of data. However what's cool about list functions is that they can be used for quick extraction of data.
You can consider an email address as a list which uses the @ character as a delimiter. Because of this, you can then use listFirst() and listLast() to quickly grab the two portions of the email address.
<cfset userName = listFirst(emailAddress,"@")>
<cfset domainName = listLast(emailAddress,"@")>
ColdFusion's list functions use the comma character as the default delimiter. Notice in the code above that we explicitly tell ColdFusion to use the @ character instead.
This question was written by Tariq Ahmed
It was last updated on February 2, 2006.
Categories
StringsLists