FormattedValueOrString(begin_str, str, end_str, default_str)
Last updated June 26, 2002
Version: 1 | Requires: CF5 | Library: StrLib
Description:
Returns either a formatted value (wrapped within begin_str and end_str) or the passed default string. Useful for wrapping non-empty values in parenthesis, or in anchor tags, or for other similar conditional formattings.
Return Values:
Returns a string.
Example:
<cfset email = "me@host.com">
<cfset email2 = "">
<cfoutput>
#FormattedValueOrString("<A HREF='mailto:#email#'>", email, "</A>", "(unspecified)")#<br>
#FormattedValueOrString("<A HREF='mailto:#email2#'>", email2, "</A>", "(unspecified)")#<br>
</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
begin_str | String to prepend to output. | Yes |
str | Variable to check. | Yes |
end_str | String to append to output. | Yes |
default_str | String to return if str is empty. | Yes |
Full UDF Source:
/**
* Returns either a formatted value or the passed default string.
*
* @param begin_str String to prepend to output. (Required)
* @param str Variable to check. (Required)
* @param end_str String to append to output. (Required)
* @param default_str String to return if str is empty. (Required)
* @return Returns a string.
* @author Shawn Seley (shawnse@aol.com)
* @version 1, June 26, 2002
*/
function FormattedValueOrString(begin_str, str, end_str, default_str) {
if (str IS "") return default_str;
return begin_str & str & end_str;
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016