CFLib.org – Common Function Library Project

FormattedValueOrString(begin_str, str, end_str, default_str)

Last updated June 26, 2002

author

Shawn Seley

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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson