format(str, args)
Last updated March 10, 2013
Version: 1 | Requires: CF9 | Library: StrLib
Description:
CFML-friendly wrapper for a call to Java String's format() function.
You can read more about the syntax on Oracle's site:
http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html
Return Values:
A formatted string
Example:
format("%s is a required field", ["email"])
Explicit argument indices may be used to re-order output.
format("My last name is %2$s and my first name is %1$s", ["john","doe"])
Parameters:
Name | Description | Required |
---|---|---|
str | A format string | Yes |
args | Array of arguments referenced by the format specifiers in the format string. | Yes |
Full UDF Source:
/**
* Uses the Java String format() method to format a string in CFML.
* v0.9 by Anthony Cole
* v1.0 by Adam Cameron (renamed from sprintf to format, as this more closely reflects the underlying implementation; improved argument/variable names and tweaked the logic slightly)
*
* @param str A format string (Required)
* @param args Array of arguments referenced by the format specifiers in the format string. (Required)
* @return A formatted string
* @author Anthony Cole (acole76@gmail.com)
* @version 1.0, March 10, 2013
*/
string function format(required string str, required array args){
return str.format(str, args);
}
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