cfpop Example
cfpop lets you retrieve and manipulate mail in a POP3 mailbox. This view-only example shows how to create one feature of a mail client, to display the mail headers in a POP3 mailbox.
To execute this, un-comment this code and run with a mail-enabled CF Server. #GetParks.
cfqueryparam Description Verifies the data type of a query parameter and, for DBMSs that support bind variables, enables ColdFusion to use bind variables in the SQL statement. Bind variable usage enhances performance when executing a cfquery statement multiple times. This tag is nested within a cfquery tag, embedded in a query SQL statement. If you specify optional parameters, this tag performs data validation.
Attributes Attribute Req/Opt value Required Default Description Value that ColdFusion passes to the right of the comparison operator in a where clause. If CFSQLType is a date or time option, ensure that the date value uses your DBMS-specific date format. Use the CreateODBCDateTime or DateFormat and TimeFormat functions to format the date value.
Usage Use the cfqueryparam tag in any SQL statement (for example, SELECT, INSERT, UPDATE, and DELETE) that uses ColdFusion variables. You cannot use the cfquery cachedAfter or cachedWithin attributes with cfqueryparam. For maximum validation of string data, specify the maxlength attribute. This tag does the following: • • • • Allows the use of SQL bind parameters, which improves performance. Ensures that variable data matches the specified SQL type.
ColdFusion JDBC DB2 Informix Oracle MSSQL CF_SQL_CHAR CHAR Char char, nchar char, nchar char, nchar, unique identifier CF_SQL_CLOB CLOB Clob clob clob,nclob CF_SQL_DATE DATE Date date, datetime, year to day CF_SQL_DECIMAL DECIMAL Decimal decimal, money number decimal, money, small money CF_SQL_DISTINCT DISTINCT CF_SQL_DOUBLE DOUBLE Double CF_SQL_FLOAT FLOAT Float float number float CF_SQL_IDSTAMP CHAR Char char, nchar char, nchar char, nchar, unique identifier
ColdFusion JDBC DB2 Informix Oracle CF_SQL_TIMESTAMP TIMESTAMP Timestamp datetime date year to fraction(5) , datetime year to second CF_SQL_TINYINT TINYINT CF_SQL_VARBINARY VARBINARY Rowid CF_SQL_VARCHAR VARCHAR Varchar MSSQL datetime, smalldate time tinyint raw varchar, nvarchar, lvarchar varbinary varchar2, varchar, nvarchar2 nvarchar, sysname Example You Selected the following employees #name# Email: #email#
SELECT * FROM Messages cfset Example cfset sets and reassigns values to local or global variables within a page. For example, the variable NumRecords has been declared on this page to hold the number of records returned from query (#NumRecords#).
cfsetting Description Controls aspects of page processing, such as the output of HTML code in pages.
Usage The cfsetting requestTimeout attribute replaces the use of requestTimeOut within a URL. To enforce a page timeout, detect the URL variable and use code such as the following to change the page timeout: You can use this tag to manage whitespace in ColdFusion output pages. If you nest cfsetting tags: to make HTML output visible, you must match each enableCFoutputOnly = "Yes" statement with an enableCFoutputOnly = "No" statement.
cfsilent Description Suppresses output produced by CFML within a tag’s scope. Category Data output tags, Page processing tags Syntax ... See also cfcache, cfflush, cfheader, cfhtmlhead, cfinclude, cfsetting; Chapter 9, “Writing and Calling User-Defined Functions,” in ColdFusion MX Developer’s Guide Usage This tag requires an end tag.
cfslider Description Puts a slider control, for selecting a numeric value from a range, in a ColdFusion form. The slider moves over the slider groove. As the user moves the slider, the current value displays. Used within a cfform tag. Not supported with Flash forms.
Attributes Attribute Req/Opt Default Description name Required Name of cfslider control. label Optional Label to display with control; for example, "Volume" This displays: "Volume %value%" To reference the value, use "%value%". If %% is omitted, slider value displays directly after label. range Optional scale Optional value Optional onValidate Optional Custom JavaScript function to validate user input; in this case, a change to the default slider value. Specify only the function name.
Attribute Req/Opt Default Description vertical Optional • Yes: renders slider in browser vertically. You must set width and height attributes; ColdFusion does not automatically swap width and height values. • No: renders slider horizontally. bgColor Optional Background color of slider label. For a hexadecimal value, use the form: bgColor = "##xxxxxx", where x = 0-9 or A-F; use two number signs or none.
If the following conditions are true, a user’s selection from query data that populates this tag’s options continues to display after the user submits the form: • The cfform preserveData attribute is set to "Yes". • The cfform action attribute posts to the same page as the form itself (this is the default), or the action page has a form that contains controls with the same names as corresponding controls on the user entry form. For more information, see the cfform tag entry.
cfstoredproc Description Executes a stored procedure in a server database. It specifies database connection information and identifies the stored procedure.
Attribute Req/Opt Default Description returnCode Optional No result Optional • Yes: populates cfstoredproc.statusCode with status code returned by the stored procedure. • No Specifies a name for the structure in which cfstoredproc returns the statusCode and ExecutionTime variables. If set, this value replaces cfstoredproc as the prefix to use when accessing those variables. For more information, see the Usage section. Usage Use this tag to call a database stored procedure.
---> SELECT Emp_ID, FirstName, LastName, EMail, Phone, Department FROM Employees cfswitch Example You've Thrown an Error #cfcatch.message# The contents of the tag stack are:
cftimer Description Displays execution time for a specified section of CFML code. ColdFusion MX displays the timing information along with any output produced by the timed code. Note: To permit this tag to execute, you must enable the Timer Information option under Debugging Settings in the ColdFusion MX Administrator.
Example1 ...
from Departments Scroll down to CFTimer Times heading to see timing information ...
cftrace Description Displays and logs debugging data about the state of an application at the time the cftrace tag executes. Tracks runtime logic flow, variable values, and execution time. Displays output at the end of the request or in the debugging section at the end of the request; or, in Dreamweaver MX and later, in the Server Debug tab of the Results window. ColdFusion logs cftrace output to the file logs\cftrace.log, in the ColdFusion installation directory.
Attribute Req/Opt Default Description type Optional Corresponds to the cflog type attribute; displays an appropriate icon: • Information • Warning • Error • Fatal Information var Optional Information The name of a simple or complex variable to display. Useful for displaying a temporary value, or a value that does not display on any CFM page. Usage You cannot put application code within this tag. (This avoids problems that can occur if you disable debugging.
cftransaction Description For enterprise database management systems that support transaction processing, instructs the database management system to treat multiple database operations as a single transaction. Provides database commit and rollback processing. See the documentation for your database management system to determine whether it supports SQL transaction processing.
Usage If you do not specify a value for the action attribute, automatic transaction processing proceeds as follows: • If the cfquery operations within the transaction block complete without an error, the transaction is committed. • If a cfquery tag generates an error within a cftransaction block, all cfquery operations in the transaction roll back. If you do not specify a value for the isolation attribute, ColdFusion uses the default isolation level for the associated database.
cftree Description Inserts a tree control in a form. Validates user selections. Used within a cfform tag block. You can use a ColdFusion query to supply data to the tree.
History ColdFusion MX 7: • Added the format attribute and support for generating Flash and XML and object output. • Added enabled, onChange, style, tooltip, and visible attributes (Flash format only). ColdFusion MX: Changed behavior: ColdFusion renders a tree control regardless of whether there are any treeitems within it. Attributes Note: In XML format, ColdFusion MX passes all attributes to the XML.
Attribute Req/Opt Default Format Description appendKey Optional; Yes All • Yes: if you use cftreeitem href attributes, ColdFusion appends a CFTREEITEMKEY query string variable with the value of the selected tree item to the cfform action URL. • No: does not append the tree item value to the URL. highlightHref Optional; Yes Applet, Object • Yes: highlights as a link the displayed value for any cftreeitem tag that specifies an href attribute. • No: disables highlighting.
Attribute Req/Opt Default Format Description align Optional; Applet, object • • • • • • • • • border Optional; Yes Applet, object • Yes: displays a border around the tree control. • No hScroll Optional; Yes Applet, object • Yes: permits horizontal scrolling. • No vScroll Optional; Yes Applet, object • Yes: permits vertical scrolling.
Note: All attributes are passed to the XML generated in XML format, but no ColdFusion MX skin interprets cftree XML. Usage This tag must be in a cfform tag block. The applet format tree requires the client to download a Java applet. Also, if the client does not have an up-to-date Java plugin installed, the system might also have to download an updated Java plugin to display an applet format tree. The Flash format tree uses a Flash control, and can be embedded in an HTML format cfform tag.
The structure variable name is specified by the cftree name attribute. The top level of the structure has two types of entries: • Attribute settings • A children array Attribute settings The structure has top-level entries with the values of the following cftree attributes: align completePath highlightHref lookAndFeel appendKey delimiter hScroll name bold fontWeight italic vscroll border Children array The top-level children entry is an array of items entries.
from CourseList c, Departments d where d.Dept_ID = c.Dept_ID order by d.dept_Name, c.corName, c.
You Requested information on #URL.cftreeitemKey#; User ID #URL.user_ID#
Serializing CFML data... Resulting WDDX packet is: #wddxText# Deserializing WDDX packet... The recordset data is:...
cfxml Description Creates a ColdFusion XML document object that contains the markup in the tag body. This tag can include XML and CFML tags. ColdFusion processes the CFML code in the tag body, and then assigns the resulting text to an XML document object variable, which is always stored in Unicode.
To change the declaration to specify another encoding, use the Replace function. To specify the encoding of the text that is returned to a browser or other application, use the cfcontent tag.
CHAPTER 3 ColdFusion Functions This chapter lists and categorizes ColdFusion Markup Language (CFML) functions. Contents Function list. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449 Functions by category . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452 Function changes since ColdFusion 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ArrayPrepend GetSOAPResponseHeader QueryAddRow ArrayResize GetTempDirectory QueryNew ArraySet GetTempFile QuerySetCell ArraySort GetTickCount QuotedValueList ArraySum GetTimeZoneInfo Rand ArraySwap GetToken Randomize ArrayToList Hash RandRange Asc Hour REFind ASin HTMLCodeFormat REFindNoCase Atn HTMLEditFormat ReleaseComObject BinaryDecode IIf RemoveChars BinaryEncode IncrementValue RepeatString BitAnd InputBaseN Replace BitMaskClear Insert ReplaceList BitMaskR
CreateTimeSpan IsXmlElem StructCopy CreateUUID IsXmlNode StructCount DateAdd IsXmlRoot StructDelete DateCompare JavaCast StructFind DateConvert JSStringFormat StructFindKey DateDiff LCase StructFindValue DateFormat Left StructGet DatePart Len StructInsert Day ListAppend StructIsEmpty DayOfWeek ListChangeDelims StructKeyArray DayOfWeekAsString ListContains StructKeyExists DayOfYear ListContainsNoCase StructKeyList DaysInMonth ListDeleteAt StructNew DaysInYear ListFind
GetBaseTagList LSIsNumeric XmlParse GetBaseTemplatePath LSNumberFormat XmlSearch GetClientVariablesList LSParseCurrency XmlTransform GetCurrentTemplatePath LSParseDateTime XmlValidate GetDirectoryFromPath LSParseEuroCurrency Year GetEncoding LSParseNumber YesNoFormat GetException LSTimeFormat GetFileFromPath LTrim Functions by category The following tables list functions by their category or purpose. Array functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ArrayDeleteAt ArrayMin ArraySort ListToArray ArrayInsertAt ArrayNew ArraySum ArrayToList Hash ToScript BinaryDecode LCase ToString XmlParse BinaryEncode ListToArray URLDecode XmlTransform CharsetDecode ToBase64 URLEncodedFormat CharsetEncode ToBinary Val Conversion functions XmlFormat Date and time functions CreateDate DateFormat GetTimeZoneInfo MonthAsString CreateDateTime DatePart Hour Now CreateODBCDate Day IsDate ParseDateTime CreateODBCDateTime DayOfWeek IsLeapYea
Display and formatting functions CJustify HTMLCodeFormat LSIsDate NumberFormat DateFormat HTMLEditFormat LSNumberFormat ParagraphFormat DecimalFormat LJustify LSParseCurrency RJustify DollarFormat LSCurrencyFormat LSParseDateTime StripCR FormatBaseN LSDateFormat LSParseEuroCurrency TimeFormat GetLocale LSEuroCurrencyFormat LSParseNumber GetLocaleDisplayName LSIsCurrency YesNoFormat LSTimeFormat Dynamic evaluation functions DE Evaluate IIf SetVariable Extensibility functions Creat
Compare Left ListGetAt ListValueCount CompareNoCase Len ListInsertAt ListValueCountNoCase Decrypt ListAppend ListLast ReplaceList Encrypt ListChangeDelims ListLen Find ListContains ListPrepend Mathematical functions Abs BitNot FormatBaseN Randomize ACos BitOr IncrementValue RandRange ArrayAvg BitSHLN InputBaseN Round ArraySum BitSHRN Int Sgn ASin BitXor Log Sin Atn Ceiling Log10 Sqr BitAnd Cos Max Tan BitMaskClear DecrementValue Min BitMaskRead Exp Pi BitM
String-processing functions process any of these characters (including ASCII 0 (NUL) characters), and continue counting subsequent characters of the string, if any. (In earlier releases, some string-processing functions processed the ASCII 0 (NUL) character, but did not process subsequent characters of the string.
GetContextRoot GetMetaData SetLocale GetCurrentTemplatePath GetMetricData SetProfileString GetDirectoryFromPath GetPageContext WriteOutput GetEncoding GetProfileSections GetException GetProfileString XML functions AddSOAPRequestHeader IsSOAPRequest IsXmlRoot XmlGetNodeType AddSOAPResponseHeader IsXML IsWDDX XmlNew GetSOAPRequest IsXmlAttribute ToString XmlParse GetSOAPRequestHeader IsXmlDoc XmlChildPos XmlSearch GetSOAPResponse IsXmlElem XmlElemNew XmlTransform XmlFormat Xml
Function Parameter or value Added in this ColdFusion release GetAuthUser All ColdFusion MX GetContextRoot All ColdFusion MX 7 GetEncoding All ColdFusion MX GetLocaleDisplayName 458 ColdFusion MX 7 GetMetaData All ColdFusion MX GetPageContext All ColdFusion MX GetProfileSections All ColdFusion MX GetSOAPRequest All ColdFusion MX 7 GetSOAPRequestHeader All ColdFusion MX 7 GetSOAPResponse All ColdFusion MX 7 GetSOAPResponseHeader All ColdFusion MX 7 Hash algorithm and encod
Function Parameter or value Added in this ColdFusion release ToScript All ColdFusion MX 7 URLDecode charset parameter ColdFusion MX URLEncodedFormat charset parameter ColdFusion MX URLSessionFormat All ColdFusion MX Wrap All ColdFusion MX 6.
Obsolete functions, parameters, and values The following functions, parameters, and values are obsolete. Do not use them in ColdFusion applications. They do not work in releases later than ColdFusion 5.
CHAPTER 3 ColdFusion Functions Abs Description Absolute-value function. The absolute value of a number is the number without its sign. Returns The absolute value of a number. Category Mathematical functions Function syntax Abs(number) See also Sgn Parameters Parameter Description number A number Example Abs Example The absolute value of the following numbers: 1,3,-4,-3.2,6 is #Abs(1)#,#Abs(3)#,#Abs(-4)#,#Abs(-3.
ACos Description Arccosine function. The arccosine is the angle whose cosine is number. Returns The arccosine, in radians, of a number. Category Mathematical functions Function syntax ACos(number) See also Cos, Sin, ASin, Tan, Atn, Pi Parameters Parameter Description number Cosine of an angle. The value must be between -1.0 and 1.0, inclusive. Usage The range of the result is 0 to π. To convert degrees to radians, multiply degrees by π/180. To convert radians to degrees, multiply radians by 180/π.
AddSOAPRequestHeader Description Adds a SOAP header to a web service request before making the request. Returns Nothing. Category XML functions History ColdFusion MX 7: Added this function.
AddSOAPRequestHeader Example // Create the web service object. ws = CreateObject("webservice", "http://localhost/soapheaders/ headerservice.cfc?WSDL"); // Set the username header as a string.
AddSOAPResponseHeader Description Adds a SOAP response header to a web service response. Call only from within a CFC web service function that is processing a request as a SOAP web service. Returns Nothing Category XML functions History ColdFusion MX 7: Added this function.
Save the following code as headerservice.cfc in a folder called soapheaders under your web root. Test its operation, and specifically the operation of the AddSOAPResponseHeader function, by executing the examples that invoke this web service. For example, see the example for AddSOAPRequestHeader. AddSOAPResponseHeader Example This is what the array looks like after delete: #DaysArray[1][1]# #DaysArray[1][2]# #DaysArray[2][1]# #DaysArray[2][2]#
ArrayInsertAt Description Inserts a value into an array. Array elements whose indexes are equal to or greater than the new position are incremented by one. The array length increases by one. Returns True, on successful completion.
Add an element before position 3: #ArrayInsertAt(DaysArray,3,"Wednesday")# Now output the array as a list: #ArrayToList(DaysArray)# Enter the sine of the angle to calculate, in degrees and radians. The value must be between 1 and -1,inclusive.
Atn Description Arctangent function. The arctangent is the angle whose tangent is number. Returns The arctangent, in radians, of a number. Category Mathematical functions Function syntax Atn(number) See also Atn, Sin, ASin, Cos, ACos, Pi Parameters Parameter Description number Tangent of an angle Usage The range of the result is -π/2 to π/2 radians. To convert degrees to radians, multiply degrees by π/180. To convert radians to degrees, multiply radians by 180/π.
AuthenticatedContext Description This function is obsolete. Use the newer security tools; see “Conversion functions” on page 453 and Chapter 16, “Securing Applications” in ColdFusion MX Developer’s Guide. History ColdFusion MX: This function is obsolete. It does not work in ColdFusion MX and later ColdFusion releases.
AuthenticatedUser Description This function is obsolete. Use the newer security tools; see “Conversion functions” on page 453 and Chapter 16, “Securing Applications” in ColdFusion MX Developer’s Guide. History ColdFusion MX: This function is obsolete. It does not work in ColdFusion MX and later ColdFusion releases.
BinaryDecode Description Converts a string to a binary object. Used to convert binary data that has been encoded into string format back into binary data. Returns A binary object. Category Conversion functions, String functions Function syntax BinaryDecode(string, binaryencoding) See also BinaryEncode, CharsetEncode, CharsetDecode History ColdFusion MX 7: Added this function. Parameters Parameter Description string A string containing encoded binary data.
Example The following example reads a GIF file as binary data, converts it to a binary-encoded string, converts the binary-encoded data back to binary data and writes the result to a file. It displays the encoded string and the image in the output file. Binary Encoding Conversion Example
BitAnd Description Performs a bitwise logical AND operation. Returns The bitwise AND of two long integers. Category Mathematical functions Function syntax BitAnd(number1, number2) See also BitNot, BitOr, BitXor Parameters Parameter Description number1 32-bit signed integer number2 32-bit signed integer Usage Bit functions operate on 32-bit signed integers, in the range -2147483648 – 2147483647. Example BitAnd Example Returns the bitwise AND of two long integers.
BitMaskClear Description Performs a bitwise mask clear operation. Returns A number, bitwise cleared, with length bits beginning at start.
BitMaskRead Description Performs a bitwise mask read operation. Returns An integer, created from length bits of number, beginning at start.
BitMaskSet Description Performs a bitwise mask set operation. Returns A number, bitwise masked with length bits of mask beginning at start.
BitNot Description Performs a bitwise logical NOT operation. Returns A number; the bitwise NOT of a long integer. Category Mathematical functions Function syntax BitNot(number) See also BitAnd, BitOr, BitXor Parameters Parameter Description number 32-bit signed integer Usage Bit functions operate on 32-bit signed integers, in the range -2147483648 – 2147483647. Example BitNot Example Returns the bitwise NOT of a long integer.
BitOr Description Performs a bitwise logical OR operation. Returns A number; the bitwise OR of two long integers. Category Mathematical functions Function syntax BitOr(number1, number2) See also BitAnd, BitNot, BitXor Parameters Parameter Description number1 32-bit signed integer number2 32-bit signed integer Usage Bit functions operate on 32-bit signed integers, in the range -2147483648 – 2147483647. Example BitOr Example Returns the bitwise OR of two long integers.
BitSHLN Description Performs a bitwise shift-left, no-rotation operation. Returns A number, bitwise shifted without rotation to the left by count bits. Category Mathematical functions Function syntax BitSHLN(number, count) See also BitSHRN Parameters Parameter Description number 32-bit signed integer count Integer, in the range 0-31, inclusive; number of bits to shift the number Usage Bit functions operate on 32-bit signed integers, in the range -2147483648 – 2147483647.
BitSHRN Description Performs a bitwise shift-right, no-rotation operation. Returns A number, bitwise shifted, without rotation, to the right by count bits. Category Mathematical functions Function syntax BitSHRN(number, count) See also BitSHLN Parameters Parameter Description number 32-bit signed integer count Integer, in the range 0-31, inclusive. Number of bits to shift the number Usage Bit functions operate on 32-bit signed integers, in the range -2147483648 – 2147483647.
BitXor Description Performs a bitwise logical XOR operation. Returns Bitwise XOR of two long integers. Category Mathematical functions Function syntax BitXor(number1, number2) See also BitAnd, BitNot, BitOr Parameters Parameter Description number1 32-bit signed integer number2 32-bit signed integer Usage Bit functions operate on 32-bit signed integers, in the range -2147483648 – 2147483647. Example BitXOr Example Returns the bitwise XOR of two long integers.
Ceiling Description Determines the closest integer that is greater than a specified number. Returns The closest integer that is greater than a given number. Category Mathematical functions Function syntax Ceiling(number) See also Int, Fix, Round Parameters Parameter Description number A real number Example Ceiling Example The ceiling The ceiling The ceiling The ceiling of of of of 3.4 is #ceiling(3.4)# 3 is #ceiling(3)# 3.8 is #ceiling(3.8)# -4.
CharsetDecode Description Converts a string to a binary representation. Returns A binary object that represents the string. Category Conversion functions, String functions Function syntax CharsetDecode(string, encoding) See also BinaryDecode, BinaryEncode, CharsetEncode; “Determining the page encoding of server output” in Chapter 17, “Developing Globalized Applications,” in ColdFusion MX Developer’s Guide History ColdFusion MX 7: Added this function.
Example The following example uses the CharsetDecode function to convert a string from a form to a binary object, and uses the CharsetEncode function to convert it back to the original value. You can change the character encoding that ColdFusion uses for the conversion. Notice that if you select the Asian language encodings, characters that are not in the specified character set do get successfully converted.
510 Chapter 3: ColdFusion Functions
CharsetEncode Description Uses the specified encoding to convert binary data to a string. Returns A string representation of the binary object. Category Conversion functions, String functions Function syntax CharsetEncode(binaryobject, encoding) See also BinaryDecode, BinaryEncode, CharsetDecode; “Determining the page encoding of server output” in Chapter 17, “Developing Globalized Applications,” in ColdFusion MX Developer’s Guide History ColdFusion MX 7: Added this function.
Example The following example uses the CharsetDecode function to convert a string from a form to a binary object, and uses the CharsetEncode function to convert it back to the original value. You can change the character encoding that ColdFusion uses for the conversion. Notice that if you select the Asian language encodings, characters that are not in the specified character set do get successfully converted.
CharsetEncode 513
Chr Converts a numeric value to a UCS-2 character. Returns A character with the specified UCS-2 character code. Category String functions Function syntax Chr(number) See also Asc History ColdFusion MX: Changed Unicode support: ColdFusion supports the Java UCS-2 representation of Unicode characters, up to a value of 65535. (Earlier releases supported 1-255.
maxlength="5" > Chr 515
CJustify Description Centers a string in a field length. Returns String, center-justified by adding spaces before or after the input parameter. If length is less than the length of the input parameter string, the string is returned unchanged. Category Display and formatting functions, String functions Function syntax Cjustify(string, length) See also LJustify, RJustify Parameters Parameter Description string A string or a variable that contains one. May be empty.
Compare Description Performs a case-sensitive comparison of two strings. Returns • -1, if string1 is less than string2 • 0, if string1 is equal to string2 • 1, if string1 is greater than string2 Category String functions Function syntax Compare(string1, string2) See also CompareNoCase, Find Parameters Parameter Description string1 A string or a variable that contains one string2 A string or a variable that contains one Usage Compares the values of corresponding characters in string1 and string2.
This is the default case
Formatted with CreateDate and DateFormat: #DateFormat(CreateDate(form.year, form.month, form.day), "mmm-ddyyyy")# Formatted with CreateDateTime and DateFormat: #DateFormat(CreateDateTime(form.year, form.month, form.day, 12,13,0))# Formatted with CreateODBCDate and DateFormat: #DateFormat(CreateODBCDate(yourDate), "mmmm d, yyyy")# Formatted with CreateODBCDateTime and DateFormat: #DateFormat(CreateODBCDateTime(yourDate), "d/m/yy")# PAGE 525
CreateDateTime Description Creates a date-time object. Returns A date/time value. Category Date and time functions Function syntax CreateDateTime(year, month, day, hour, minute, second) See also CreateDate, CreateTime, CreateODBCDateTime, Now; “Date-time functions and queries when ODBC is not supported” in Chapter 3, “Using ColdFusion Variables,” in ColdFusion MX Developer’s Guide Parameters Parameter Description year Integer in the range 0-9999. Integers in the range 0-29 are converted to 20002029.
The same value can be formatted with DateFormat: - Formatted with CreateDate and DateFormat: #DateFormat(CreateDate(form.year, form.month, form.day), "mmm-dd-yyyy")#
- Formatted with CreateDateTime and DateFormat: #DateFormat(CreateDateTime(form.year, form.month, form.day, form.hour, form.minute, form.
-
CreateObject Description Creates a ColdFusion object, of a specified type. Returns An object, of the specified type. Note: You can enable and disable this function in the ColdFusion Administrator, ColdFusion Basic Security, Tag Restrictions page. Category Extensibility functions History ColdFusion MX 7: For web service object: added the portName parameter, which specifies a port named in the service element of the WSDL.
-
CreateObject: COM object Description The CreateObject function can create a Component Object Model (COM) object. To create a COM object, you must provide this information: • The object’s program ID or filename • The methods and properties available to the object through the IDispatch interface • The arguments and return types of the object's methods For most objects, you can get this information from the OLEView utility. Note: On UNIX, this function does not support COM objects. Returns A COM object.
-
Usage The following example creates the Windows Collaborative Data Objects (CDO) for NTS NewMail object to send mail. You would use this code within a cfscript tag. Mailer = CreateObject("COM", "CDONTS.
-
CreateObject: component object Description The CreateObject function can create an instance of a ColdFusion component (CFC) object. Returns A component object. Function syntax CreateObject(type, component-name) See also Chapter 10, “Building and Using ColdFusion Components” in ColdFusion MX Developer’s Guide Parameters Parameter Description type Type of object to create.
-
CreateObject: CORBA object Description The CreateObject function can call a method on a CORBA object. The object must be defined and registered for use. Returns A handle to a CORBA interface. Function syntax CreateObject(type, context, class, locale) See also Chapter 38, “Integrating COM and CORBA Objects in CFML Applications” in ColdFusion MX Developer’s Guide History See the History section of the main CreateObject function page. Parameters Parameter Description type Type of object to create.
-
ColdFusion Enterprise supports CORBA through the Dynamic Invocation Interface (DII). To use this function with CORBA objects, you must provide the name of the file that contains a string version of the IOR, or the object’s naming context in the naming service. You must provide the object’s attributes, method names and method signatures. This function supports user-defined types (structures, arrays, and sequences). Example myobj = CreateObject("corba", "d:\temp\tester.
-
CreateObject: Java or EJB object Description The CreateObject function can create a Java object, and, by extension, an EJB object. Returns A Java object. Function syntax CreateObject(type, class) Parameters Parameter Description type Type of object to create. • com • corba • java • component • webservice class A Java class name Usage Any Java class available in the class path that is specified in the ColdFusion Administrator can be loaded and used from ColdFusion with the CreateObject function.
-
CreateObject: web service object Description This function can create a web service object. Returns A web service object. Function syntax CreateObject(type, urltowsdl [, portname ]) Parameters Parameter Description type Type of object to create. • com • corba • java • component • webservice urltowsdl WSDL file URL; location of web service portname The port name for the web service. This value is case-sensitive and corresponds to the port element’s name attribute under the service element.
-
CreateODBCDate Description Creates an ODBC date object. Returns A date object, in normalized ODBC date format. Category Date and time functions Function syntax CreateODBCDate(date) See also CreateDate, CreateODBCDateTime Parameters Parameter Description date Date or date/time object in the range 100 AD–9999 AD. Usage This function does not parse or validate values.
-
#DateFormat(CreateDateTime(form.year, form.month, form.day, form.hour, form.minute, form.second))# - Formatted with CreateODBCDate and DateFormat: #DateFormat(CreateODBCDate(yourDate), "mmmm d, yyyy")#
- Formatted with CreateODBCDateTime and DateFormat: #DateFormat(CreateODBCDateTime(yourDate), "d/m/yy")#
PAGE 537
CreateODBCDateTime Description Creates an ODBC date-time object. Returns A date-time object, in ODBC timestamp format. Category Date and time functions Function syntax CreateODBCDateTime(date) See also CreateDateTime, CreateODBCDate, CreateODBCTime, Now; “Evaluation and type conversion issues” in Chapter 3, “Using ColdFusion Variables,” in ColdFusion MX Developer’s Guide Parameters Parameter Description date Date-time object in the range 100 AD–9999 AD.
Formatted with CreateODBCDate and DateFormat: #DateFormat(CreateODBCDate(yourDate), "mmmm d, yyyy")# Formatted with CreateODBCDateTime and DateFormat: #DateFormat(CreateODBCDateTime(yourDate), "d/m/yy")# PAGE 539
CreateODBCTime Description Creates an ODBC time object. Returns A time object, in ODBC timestamp format. Category Date and time functions Function syntax CreateODBCTime(date) See also CreateODBCDateTime, CreateTime, “Evaluation and type conversion issues” in Chapter 3, “Using ColdFusion Variables,” in ColdFusion MX Developer’s Guide Parameters Parameter Description date Date/time object in the range 100 AD–9999 AD.
CreateTime Description Creates a time variable. Returns A time variable. Category Date and time functions Function syntax CreateTime(hour, minute, second) See also CreateODBCTime, CreateDateTime; “Evaluation and type conversion issues” in Chapter 3, “Using ColdFusion Variables,” in ColdFusion MX Developer’s Guide Parameters Parameter Description hour Number in the range 0–23 minute Number in the range 0–59 second Number in the range 0–59 Usage CreateTime is a subset of CreateDateTime.
MESSAGE="You must enter a value for seconds (0-59)" VALIDATE="integer" REQUIRED="Yes"> CreateTime 541
CreateTimeSpan Description Creates a date/time object that defines a time period. You can add or subtract it from other datetime objects and use it with the cachedWithin attribute of cfquery. Returns A date-time object.
cachedWithin = "#CreateTimeSpan(0, 6, 0, 0)#"> SELECT PARKNAME, REGION, STATE FROM Parks ORDER by ParkName, State Park Name | Region | State | SELECT UserName, Subject, Posted FROM Messages This example uses DateAdd to determine when a message in the database will expire.
DateCompare Description Performs a full date/time comparison of two dates. Returns • -1, if date1 is earlier than date2 • 0, if date1 is equal to date2 • 1, if date1 is later than date2 Category Date and time functions Function syntax DateCompare("date1", "date2" [, "datePart"]) See also CreateDateTime, DatePart Parameters Parameter Description date1 Date/time object, in the range 100 AD–9999 AD. date2 Date/time object, in the range 100 AD–9999 AD. datePart Optional. String.
#TimeFormat(FORM.date2)# (Date The dates are not equal #DateFormat(FORM.date1)# #TimeFormat(FORM.date1)# (Date to #DateFormat(FORM.date2)# #TimeFormat(FORM.date2)# (Date The dates are equal! #DateFormat(FORM.date1)# #TimeFormat(FORM.date1)# (Date than #DateFormat(FORM.date2)# #TimeFormat(FORM.
550 Chapter 3: ColdFusion Functions
DateConvert Description Converts local time to Coordinated Universal Time (UTC), or UTC to local time. The function uses the daylight savings settings in the executing computer to compute daylight savings time, if required. Returns UTC- or local-formatted time object. Category Date and time functions Function syntax DateConvert("conversion-type", "date") See also GetTimeZoneInfo, CreateDateTime, DatePart Parameters Parameter Description conversion-type • local2Utc: Converts local time to UTC time.
Your date and time value, converted to Coordinated Universal Time (UTC): #yourUTC#. Your UTC date and time, converted back to local date and time: #DateConvert("utc2local", yourUTC)#. Type the date and time, and press Enter to see the conversion.
Enclose string constant dates in quotation marks. If the text contains only numbers (such 1932), and is not surrounded by quotation marks, ColdFusion interprets it as a date/time object, resulting in an incorrect value. Example
Please enter two valid date/time values, formatted like this: #DateFormat(Now())#
Usage When passing a date/time object as a string, you must enclose it in quotation marks. Otherwise, it is interpreted as a numeric representation of a date/time object. Note: You can pass the CreateDate function or Now function as the date parameter of this function; for example: #DateFormat(CreateDate(2001, 3, 3))# Date and time values in database query results can vary in sequence and formatting unless you use functions to format them.
DatePart Description Extracts a part from a date value. Returns Part of a date, as an integer. Category Date and time functions Function syntax DatePart("datepart", "date") See also DateAdd, DateConvert History ColdFusion MX 6.1: Added the datepart character L or l to represent milliseconds.
- year: #DatePart("yyyy", todayDate)#
- quarter: #DatePart("q", todayDate)#
- month: #DatePart("m", todayDate)#
- day of year: #DatePart("y", todayDate)#
- day: #DatePart("d", todayDate)#
- weekday: #DatePart("w", todayDate)#
- week: #DatePart("ww", todayDate)#
- hour: #DatePart("h", todayDate)#
- minute: #DatePart("n", todayDate)#
- second: #DatePart("s", todayDate)#
DatePart 559
Day Description Determines the day of the month, in a date. Returns The ordinal for the day of the month, ranging from 1 to 31. Category Date and time functions Function syntax Day("date") See also DayOfWeek, DayOfWeekAsString, DayOfYear, DaysInMonth, DaysInYear, FirstDayOfMonth Parameters Parameter Description date Date/time object, in the range 100 AD–9999 AD. Usage When passing a date/time object as a string, you must enclose it in quotation marks.
DayOfWeek Description Determines the day of the week, in a date. Returns The ordinal for the day of the week, as an integer in the range 1 (Sunday) to 7 (Saturday). Category Date and time functions Function syntax DayOfWeek("date") See also Day, DayOfWeekAsString, DayOfYear, DaysInMonth, DaysInYear, FirstDayOfMonth Parameters Parameter Description date Date/time object, in the range 100 AD–9999 AD. Usage When passing a date/time object as a string, you must enclose it in quotation marks.
DayOfWeekAsString Description Determines the day of the week, in a date, as a string function. Returns The day of the week, as a string in the current locale, that corresponds to day_of_week. Category Date and time functions, String functions Function syntax DayOfWeekAsString(day_of_week) See also Day, DayOfWeek, DayOfYear, DaysInMonth, DaysInYear, FirstDayOfMonth History ColdFusion MX 7: Changed behavior. The returned string is now in the language of the current locale.
DayOfYear Description Determines the day of the year, in a date. Returns The ordinal value of day of the year, as an integer. Category Date and time functions Function syntax DayOfYear("date") See also Day, DayOfWeek, DayOfWeekAsString, DaysInMonth, DaysInYear, FirstDayOfMonth Parameters Parameter Description date Date/time object, in the range 100 AD–9999 AD. Usage This function accounts for leap years. When passing a date/time object as a string, you must enclose it in quotation marks.
DaysInMonth Description Determines the number of days in a month. Returns The number of days in the month in Date. Category Date and time functions Function syntax DaysInMonth("date") See also Day, DayOfWeek, DayOfWeekAsString, DayOfYear, DaysInYear, FirstDayOfMonth Parameters Parameter Description date Date/time object, in the range 100 AD–9999 AD. Usage When passing a date/time object as a string, you must enclose it in quotation marks.
DaysInYear Description Determines the number of days in a year. Returns The number of days in a year. Category Date and time functions Function syntax DaysInYear("date") See also Day, DayOfWeek, DayOfWeekAsString, DayOfYear, DaysInMonth, DaysInYear, FirstDayOfMonth, IsLeapYear Parameters Parameter Description date • Date/time object, in the range 100 AD–9999 AD. Usage DaysInYear accounts for leap years. When passing a date/time object as a string, you must enclose it in quotation marks.
DE Description Escapes any double-quotation marks in the parameter and wraps the result in double-quotation marks. Returns Parameter, surrounded by double-quotation marks, with any inner double-quotation marks escaped.
The following example shows how you can use the DE function and number signs together, and shows how the function works with an IIF function: The expression is #myresult# ColdFusion processes this code as follows: 1. ColdFusion sets the variables var1 and var2 to be the strings Blue and Green. 2.
Sorry, there’s been an Error. Try a simple expression, such as "2+2". #cfcatch.
DecimalFormat Description Converts a number to a decimal-formatted string. Returns A number as a string formatted with two decimal places and a thousands separator. Category Display and formatting functions Function syntax DecimalFormat(number) See also DollarFormat, NumberFormat Parameters Parameter Description number Number to format Example DecimalFormat Function Returns a number to two decimal places.
DecrementValue Description Decrements the integer part of a number. Returns Integer part of number, decremented by one. Category Mathematical functions Function syntax DecrementValue(number) See also IncrementValue Parameters Parameter Description number Number to decrement Example DecrementValue Example Returns the integer part of a number decremented by one.
Decrypt Description Decrypts a string that is encrypted using a standard encryption technique, including strings encrypted by the Encrypt function. Returns An unencrypted string. Category Security functions, String functions Function syntax Decrypt(encrypted_string, key[, algorithm[, encoding]]) See also Duplicate, Encrypt ColdFusion MX 7: Added the algorithm and encoding parameters. Parameters Parameter Description encrypted_string String to decrypt. key String.
Usage This function uses a symmetric key-based algorithm, in which the same key is used to encrypt and decrypt a string. The parameter values must match the values used to encode string. The security of the encrypted string depends on maintaining the secrecy of the key. ColdFusion MX 7 uses the Java Cryptography Extension (JCE) and installs a Sun Java 1.4.2 runtime that includes the Sun JCE default security provider. This provider includes the algorithms listed in the Parameters section.
Select the algorithm Input your key (used for CFMX_COMPAT encryption only) Enter string to encrypt
DeleteClientVariable Description Deletes a client variable. (To test for the existence of a variable, use IsDefined.) Returns True, if the variable is successfully deleted; false, otherwise. Category Other functions Function syntax DeleteClientVariable("name") See also GetClientVariablesList History ColdFusion MX: Changed behavior: if the variable is not present, this function now returns False. (In earlier releases, it threw an error.
DirectoryExists Description Determines whether a directory exists. Returns Yes, if the specified directory exists; No, otherwise. Category System functions Function syntax DirectoryExists(absolute_path) See also FileExists Parameters Parameter Description absolute_path An absolute path Example DirectoryExists Example Enter a directory to check for existence.
Duplicate Description Returns a clone, also known as a deep copy, of a variable. There is no reference to the original variable. Returns A clone of a variable. Category Structure functions, System functions Function syntax Duplicate(variable_name) See also StructCopy, other Structure functions; “Modifying a ColdFusion XML object” in Chapter 35, “Using XML and WDDX,” in ColdFusion MX Developer’s Guide History ColdFusion MX: Changed behavior: this function can be used on XML objects.
Encrypt Description Encrypts a string using a specific algorithm and encoding method. Returns String; can be much longer than the original string. Category Security functions, String functions Function syntax Encrypt(string, key[, algorithm[, encoding]])) See also Decrypt History ColdFusion MX 7: Added the algorithm and encoding parameters. Parameters 578 Parameter Description string String to encrypt. key String. Key or seed used to encrypt the string.
Usage This function uses a symmetric key-based algorithm, in which the same key is used to encrypt and decrypt a string. The security of the encrypted string depends on maintaining the secrecy of the key. For all algorithms except the default algorithm, ColdFusion MX 7 uses the Java Cryptography Extension (JCE) and installs a Sun Java 1.4.2 runtime that includes the Sun JCE default security provider. This provider includes the algorithms listed in the Parameters section.
Exp Description Calculates the exponent whose base is e that represents number. The constant e equals 2.71828182845904, the base of the natural logarithm. This function is the inverse of Log, the natural logarithm of number. Returns The constant e, raised to the power of number.
ExpandPath Description Creates an absolute, platform-appropriate path that is equivalent to the value of relative_path, appended to the base path. This function (despite its name) can accept an absolute or relative path in the relative_path parameter The base path is the currently executing page’s directory path. It is stored in pageContext.getServletContext(). Returns A string. If the relative path contains a trailing forward slash or backward slash, the return value contains the same trailing character.
Example ExpandPath Example - View Only
Input your key (used for CFMX_COMPAT encryption only) Enter string to encrypt
GetAuthUser Description Gets the name of an authenticated user. Returns The name of an authenticated user. Category Security functions Function syntax GetAuthUser() See also IsUserInRole, cflogin, cfloginuser; Chapter 16, “Securing Applications” in ColdFusion MX Developer’s Guide History ColdFusion MX: Added this function. Usage This function works with cflogin authentication or web server authentication. It checks for a logged-in user as follows: 1. It checks for a login made with cfloginuser. 2.
GetBaseTagData Description Used within a custom tag. Finds calling (ancestor) tag by name and accesses its data. Returns An object that contains data (variables, scopes, and so on) from an ancestor tag. If there is no ancestor by the specified name, or if the ancestor does not expose data (for example, cfif ), an exception is thrown.
GetBaseTagList Description Gets ancestor tag names, starting with the parent tag. Returns A comma-delimited list of uppercase ancestor tag names, as a string. The first list element is the current tag. If the current tag is nested, the next element is the parent tag. If the function is called for a top-level tag, it returns an empty string. If an ancestor does not expose data (see GetBaseTagData), its name might not be returned.
GetBaseTemplatePath Description Gets the absolute path of an application’s base page. Returns The absolute path of the application base page, as a string.
GetClientVariablesList Description Finds the client variables to which a page has write access. Returns Comma-delimited list of non-read-only client variables, as a string. Category List functions, Other functions Function syntax GetClientVariablesList() See also DeleteClientVariable Usage The list of variables returned by this function is compatible with ColdFusion list functions. Example Initial locale's ColdFusion name: #GetLocale()# Changing locale to #form.
GetLocaleDisplayName Description Gets a locale value and displays the name in a manner that is appropriate to a specific locale. By default, gets the current locale in the current locale’s language. Returns The localized display name of the locale, in the language of the specified locale.
ws = CreateObject("webservice", "http://localhost/soapheaders/headerservice.cfc?WSDL"); ws.
GetSOAPRequestHeader Description Obtains a SOAP request header. Call only from within a CFC web service function that is processing a request as a SOAP web service. Returns A SOAP request header. Category XML functions History ColdFusion MX 7: Added this function.
GetSOAPRequestHeader Example
GetSOAPResponse Description Returns an XML object that contains the entire SOAP response after invoking a web service. Returns An XML object that contains the entire SOAP response. Category XML functions History ColdFusion MX 7: Added this function.
GetSOAPResponseHeader Description Returns a SOAP response header. Call this function from within code that is invoking a web service after making a web service request. Returns A SOAP response header. Category XML functions History ColdFusion MX 7: Added this function.
Execute the following example to see how the GetSOAPResponseHeader function operates: GetSOAPResponseHeader Example // Create the web service object ws = CreateObject("webservice", "http://localhost/soapheaders/ headerservice.
GetTempDirectory Description Gets the path of the directory that ColdFusion uses for temporary files. The directory depends on the account under which ColdFusion is running and other factors. Before using this function in an application, test to determine the directory it returns under your account. Returns The absolute pathname of a directory, including a trailing slash, as a string.
GetTempFile Description Creates a temporary file in a directory whose name starts with (at most) the first three characters of prefix. Returns Name of a temporary file, as a string.
GetTemplatePath Description This function is deprecated. Use the GetBaseTemplatePath function instead. Gets the absolute path of an application’s base page. History ColdFusion MX: Deprecated this function. It might not work, and it might cause an error, in later releases.
GetTickCount Description Returns the current value of an internal millisecond timer. Returns A string representation of the system time, in milliseconds. Category Date and time functions, System functions Function syntax GetTickCount() Usage This function is useful for timing CFML code segments or other page processing elements. The value of the counter has no meaning. To generate useful timing values, take the difference between the results of two GetTickCount calls.
GetTimeZoneInfo Description Gets local time zone information for the computer on which it is called, relative to Universal Time Coordinated (UTC). UTC is the mean solar time of the meridian of Greenwich, England, used as the basis for calculating standard time throughout the world. ColdFusion stores date and time values as date-time objects: real numbers on a universal time line.
GetToken Description Determines whether a token of the list in the delimiters parameter is present in a string. Returns The token found at position index of the string, as a string. If index is greater than the number of tokens in the string, returns an empty string. Category String functions Function syntax GetToken(string, index [, delimiters ]) See also Left, Right, Mid, SpanExcluding, SpanIncluding Parameters Parameter Description string A string or a variable that contains one.
#mystring#
The output is as follows: four, ,five, nine,zero:; nine,ten:, eleven:;twelve:;thirteen, ,four The GetToken function recognizes explicit spaces, tabs, or newline characters as the parameter delimiters (To specify a space character, the code is chr(32); a tab character, chr(9); and a newline character, chr(10).
The following is a call against mystring2: GetToken(mystring2, 2) is : #GetToken(mystring2, 2)# The output is as follows: GetToken(mystring2, 2) is : ,five,nine,zero:; The function finds the second delimiter, and returns the substring just before it that is between the first and second delimiter. This substring is ",five,nine,zero:;". Example GetToken Example
Hash Description Converts a variable-length string to a fixed-length string that can act as a “fingerprint” or unique identifier for the original string. It is not possible to convert the hash result back to the source string. Returns A string. Category Conversion functions, Security functions, String functions Function syntax Hash(string[, algorithm[, encoding]] ) History ColdFusion MX 7: Added the algorithm and encoding parameters. Parameters Parameter Description string String to hash.
Usage The result of this function is useful for comparison and validation. For example, you can store the hash of a password in a database without exposing the password. You can check the validity of the password by hashing the entered password and comparing the result with the hashed password in the database. ColdFusion MX 7 uses the Java Cryptography Extension (JCE) and installs a Sun Java 1.4.2 runtime that includes the Sun JCE default security provider.
HTMLCodeFormat Description Replaces special characters in a string with their HTML-escaped equivalents and inserts and tags at the beginning and end of the string. Returns HTML-escaped string string, enclosed in and tags. Return characters are removed; line feed characters are preserved. Characters with special meanings in HTML are converted to HTML character entities such as >.
Example myTestCFCobject.testFunc is a function.
IsDate Description Determines whether a string or Java object can be converted to a date/time value. Returns True, if string can be converted to a date/time value; False, otherwise. ColdFusion converts the Boolean return value to its string equivalent, "Yes" or "No.
IsDebugMode Description Determines whether debugging output is enabled. Returns True, if debugging mode is set in the ColdFusion Administrator; False if debugging mode is disabled. Category Decision functions Function syntax IsDebugMode() See also cfsetting Description If debugging output is enabled in ColdFusion Administrator and has not been overridden by setting the cfsetting tag showDebugOutput attribute to No, the IsDebugMode function returns Yes; No, otherwise.
IsDefined Description Evaluates a string value to determine whether the variable named in it exists. This function is an alternative to the ParameterExists function, which is deprecated. Returns True, if the variable is found, or, for a structure, if the specified key is defined; False, otherwise. The return value is False for an array or structure element referenced using bracket notation. For example, IsDefined("myArray[3]") always returns False, even if the array element myArray[3] has a value.
During the first time through this template, the variable "form.myString" has not yet been defined, so we do not try to evaluate it.
IsK2ServerDocCountExceeded Description This function is deprecated. Returns True, if the document count limit is exceeded; False, otherwise. Category Decision functions, Full-text search functions, Query functions Function syntax IsK2ServerDocCountExceeded() See also GetK2ServerDocCountLimit, IsK2ServerABroker History ColdFusion MX 6.1: Deprecated this function. It might not work, and it might cause an error, in later releases. ColdFusion 5: Added this function.
IsK2ServerOnline Description This function is deprecated because the K2Server is always running when ColdFusion is running. Returns True, if the K2Server is available to perform a search; False, otherwise. Category Decision functions, Full-text search functions, Query functions Function syntax IsK2ServerOnline() See also IsK2ServerABroker History ColdFusion MX 6.1: Deprecated this function. It might not work, and it might cause an error, in later releases. ColdFusion MX: Added this function.
IsLeapYear Description Determines whether a year is a leap year. Returns True, if year is a leap year; False, otherwise. Category Date and time functions, Decision functions Function syntax IsLeapYear(year) See also DaysInYear Parameters Parameter Description year Number representing a year Example IsLeapYear Example The year value #DE(FORM.
IsNumeric Description Determines whether a string can be converted to a numeric value. Supports numbers in U.S. number format. For other number support, use LSIsNumeric. Returns True, if string can be converted to a number; False, otherwise. Category Decision functions Function syntax IsNumeric(string) See also IsBinary, IsValid Parameters Parameter Description string A string or a variable that contains one. Example IsNumeric Example
IsNumericDate Description Evaluates whether a real number is a valid representation of a date (date/time object). Returns True, if the parameter represents a valid date/time object; False, otherwise.
678 Chapter 3: ColdFusion Functions
IsObject Description Determines whether a value is an object. Returns True, if the value represents a ColdFusion object. False if the value is any other type of data, such as an integer, string, date, or struct. Category Decision functions Function syntax IsObject(value) See also IsDate, IsNumeric, IsNumericDate, IsQuery, IsSimpleValue, IsStruct, IsWDDX, IsXmlDoc, IsXmlElem, IsXmlRoot History ColdFusion MX: Added this function.
returnVariable="myColor"> The value of myColor = #myColor# 680 Chapter 3: ColdFusion Functions
IsProtected Description This function is obsolete. Use the newer security tools; see “Conversion functions” on page 453 and Chapter 16, “Securing Applications,” in ColdFusion MX Developer’s Guide History ColdFusion MX: This function is obsolete. It does not work in ColdFusion MX and later releases.
IsQuery Description Determines whether value is a query. Returns True, if value is a query.
IsSimpleValue Description Determines the type of a value. Returns True, if value is a string, number, Boolean, or date/time value; False, otherwise.
IsSOAPRequest Description Determines whether a CFC is being called as a web service. Returns True if CFC is being called as a web service; False, otherwise. Category XML functions History ColdFusion MX 7: Added this function. Function syntax IsSOAPRequest() See also AddSOAPRequestHeader, AddSOAPResponseHeader, GetSOAPRequest, GetSOAPRequestHeader, GetSOAPResponse, GetSOAPResponseHeader; “Basic web service concepts” in Chapter 36, “Using Web Services,” in ColdFusion MX Developer’s Guide.
as XML: " & xmlusername>
IsStruct Description Determines whether a variable is a structure. Returns True, if variable is a ColdFusion structure or is a Java object that implements the java.lang.Map interface. The return value is False if the object in variable is a user-defined function (UDF).
) Employee Add Complete ---> IsStruct 687
IsUserInRole Description Determines whether an authenticated user belongs to the specified Role. Returns True, if the authenticated user, belongs to the specified Role; False, otherwise. Category Security functions, Decision functions Function syntax IsUserInRole("role_name") See also GetAuthUser, cflogin, cfloginuser; Chapter 16, “Securing Applications,” in ColdFusion MX Developer’s Guide History ColdFusion MX: Added this function.
IsValid Description Tests whether a value meets a validation or data type rule. Returns True, if the value conforms to the rule; False, otherwise.
Parameters Parameter Description type The valid format for the data; one of the following. For detailed information on validation algorithms, see “Validating form data using hidden fields” in Chapter 28, “Validating Data,” in ColdFusion MX Developer’s Guide. • any: any simple value. Returns false for complex values, such as query objects;; equivalent to the IsSimpleValue function. • array: an ColdFusion array; equivalent to the IsArray function.
Example The following example checks whether a user has submitted a numeric ID and a valid email address and phone number. If any of the submitted values does not meet the validation test, it displays an error message. The email address and phone number for user #Form.
IsWDDX Description Determines whether a value is a well-formed WDDX packet. Returns True, if the value is a well-formed WDDX packet; False, otherwise. Category Decision functions, XML functions Syntax IsWDDX(value) See also “Using WDDX” in Chapter 35, “Using XML and WDDX,” in ColdFusion MX Developer’s Guide History ColdFusion MX: Changed behavior: if the value parameter is not a WDDX packet, ColdFusion returns False. (In earlier releases, ColdFusion threw an error.
" > #packet# IsWDDX() returns #IsWDDX(packet)# IsWDDX 693
IsXML Description Determines whether a string is well-formed XML text. Returns True, if the function parameter is a string that contains well-formed XML text; False, otherwise. Category Decision functions, XML functions Function syntax IsXML(value) See also IsXmlAttribute, IsXmlDoc, IsXmlElem, IsXmlNode, IsXmlRoot, XmlParse, XmlValidate; Chapter 35, “Using XML and WDDX” in ColdFusion MX Developer’s Guide History ColdFusion MX 7: Added this function.
- 1 15.
IsXmlAttribute Description Determines whether the function parameter is an XML Document Object Model (DOM) attribute node. Returns True, if the function argument is an XML attribute node; False, otherwise. Category Decision functions, XML functions Function syntax IsXmlAttribute(value) See also IsXML, IsXmlDoc, IsXmlElem, IsXmlNode, IsXmlRoot, XmlGetNodeType, XmlValidate, Chapter 35, “Using XML and WDDX” in ColdFusion MX Developer’s Guide History ColdFusion MX 7: Added this function.
- 1 15.
IsXmlDoc Description Determines whether the function parameter is a ColdFusion XML document object. Returns True, if the function argument is an XML document object; False, otherwise. Category Decision functions, XML functions Function syntax IsXmlDoc(value) See also IsXML, IsXmlAttribute, IsXmlElem, IsXmlNode, IsXmlRoot, XmlValidate; Chapter 35, “Using XML and WDDX” in ColdFusion MX Developer’s Guide History ColdFusion MX: Added this function.
IsXmlElem Description Determines whether the function parameter is an XML document object element. Returns True, if the function argument is an XML document object element; False, otherwise. Category Decision functions, XML functions Function syntax IsXmlElem(value) See also IsXML, IsXmlAttribute, IsXmlDoc, IsXmlNode, IsXmlRoot, XmlGetNodeType, XmlValidate; Chapter 35, “Using XML and WDDX” in ColdFusion MX Developer’s Guide History ColdFusion MX: Added this function.
IsXmlNode Description Determines whether the function parameter is an XML document object node. Returns True, if the function argument is an XML document object node, including an element; False, otherwise. Category Decision functions, XML functions Function syntax IsXmlNode(value) See also IsXML, IsXmlAttribute, IsXmlDoc, IsXmlElem, IsXmlRoot, XmlGetNodeType, XmlSearch, XmlValidate; Chapter 35, “Using XML and WDDX” in ColdFusion MX Developer’s Guide History ColdFusion MX 7: Added this function.
1 15.95 Are the following XML nodes? xmlobject: #IsXmlNode(xmlobject)# xmlobject.order.items: #IsXmlNode(xmlobject.order.items)# ...
ListChangeDelims Description Changes a list delimiter. Returns A copy of the list, with each delimiter character replaced by new_delimiter. Category List functions Function syntax ListChangeDelims(list, new_delimiter [, delimiters ]) See also ListFirst, ListQualify; “Lists” in Chapter 3, “Using ColdFusion Variables,” in ColdFusion MX Developer’s Guide Parameters Parameter Description list A list or a variable that contains one. new_delimiter Delimiter string or a variable that contains one.
ListContains Description Determines the index of the first list element that contains a specified substring. Returns Index of the first list element that contains substring. If not found, returns zero. Category List functions Function syntax ListContains(list, substring [, delimiters ]) See also ListContainsNoCase, ListFind; “Lists” in Chapter 3, “Using ColdFusion Variables,” in ColdFusion MX Developer’s Guide Parameters Parameter Description list A list or a variable that contains one.
as "two", both ListContains and ListFind find it, in the second element: ListContains: The string "two" is in element #ListContains(aList, "two")# of the list. ListFind: The string "two" is in element #ListFind(aList, "two")# of the list.
ListContainsNoCase Description Determines the index of the first list element that contains a specified substring. Returns Index of the first list element that contains substring, regardless of case. If not found, returns zero.
ListDeleteAt Description Deletes an element from a list. Returns A copy of the list, without the specified element. Category List functions Function syntax ListDeleteAt(list, position [, delimiters ]) See also ListGetAt, ListSetAt, ListLen; “Lists” in Chapter 3, “Using ColdFusion Variables,” in ColdFusion MX Developer’s Guide Parameters Parameter Description list A list or a variable that contains one. position A positive integer or a variable that contains one.
The changed list: #temp2# This list element: #deleted_element# is no longer present at position three of the list.
ListFind Description Determines the index of the first list element in which a specified value occurs. Case-sensitive. Returns Index of the first list element that contains value, with matching case. If not found, returns zero. The search is case-sensitive.
SELECT FirstName, RTrim(LastName) AS LName, Phone, Department FROM Employees An employee with that exact last name was not found Employee #ListGetAt(ValueList(SearchEmpLastName.
ListFindNoCase Description Determines the index of the first list element in which a specified value occurs. Returns Index of the first list element that contains value. If not found, returns zero. The search is caseinsensitive.
SELECT FirstName, RTrim(LastName) AS LName, Phone, Department FROM Employees An employee with that exact last name was not found Employee #ListGetAt(ValueList(SearchEmpLastName.FirstName), temp)# #ListGetAt(ValueList(SearchEmpLastName.
ListFirst Description Gets the first element of a list. Returns The first element of a list. If the list is empty, returns an empty string. Category List functions Function syntax ListFirst(list [, delimiters ]) See also ListGetAt, ListLast, ListQualify; “Lists” in Chapter 3, “Using ColdFusion Variables,” in ColdFusion MX Developer’s Guide Parameters Parameter Description list A list or a variable that contains a list. delimiters A string or a variable that contains one.
ListGetAt Description Gets a list element at a specified position. Returns Index of the list element at position position. Category List functions Function syntax ListGetAt(list, position [, delimiters ]) See also ListFirst, ListLast, ListQualify, ListSetAt; “Lists” in Chapter 3, “Using ColdFusion Variables,” in ColdFusion MX Developer’s Guide Parameters Parameter Description list A list or a variable that contains one. position A positive integer or a variable that contains one.
This list of usernames who have posted messages numbers #ListLen(temp)# users.
ListInsertAt Description Inserts an element in a list. Returns A copy of the list, with value inserted at the specified position. Category List functions Function syntax ListInsertAt(list, position, value [, delimiters ]) See also ListDeleteAt, ListAppend, ListPrepend, ListSetAt; “Lists” in Chapter 3, “Using ColdFusion Variables,” in ColdFusion MX Developer’s Guide Parameters Parameter Description list A list or a variable that contains one.
ListLast Description Gets the last element of a list. Returns The last element of the list. Category List functions Function syntax ListLast(list [, delimiters ]) See also ListGetAt, ListFirst; “Lists” in Chapter 3, “Using ColdFusion Variables,” in ColdFusion MX Developer’s Guide Parameters Parameter Description list A list or a variable that contains a list. delimiters A string or a variable that contains one. Character(s) that separate list elements. The default value is comma.
Before editing the list, it is: #ValueList(GetMessageUser.Username)#. (Users who posted more than once are listed more than once.) The first user in the list is: #ListFirst(temp)# The rest of the list is: #ListRest(temp)#. (Users who posted more than once are listed more than once.
ListLen Description Determines the number of elements in a list. Integer; the number of elements in a list. Category List functions Function syntax ListLen(list [, delimiters ]) See also ListAppend, ListDeleteAt, ListInsertAt, ListPrepend; “Lists” in Chapter 3, “Using ColdFusion Variables,” in ColdFusion MX Developer’s Guide Parameters Parameter Description list A list or a variable that contains one. delimiters A string or a variable that contains one. Character(s) that separate list elements.
#ListLen(temp)# users.
ListPrepend Description Inserts an element at the beginning of a list. Returns A copy of the list, with value inserted at the first position. Category List functions Function syntax ListPrepend(list, value [, delimiters ]) See also ListAppend, ListInsertAt, ListSetAt; “Lists” in Chapter 3, “Using ColdFusion Variables,” in ColdFusion MX Developer’s Guide Parameters Parameter Description list A list or a variable that contains one. value An element or a list of elements.
ListQualify Description Inserts a string at the beginning and end of list elements. Returns A copy of the list, with qualifier before and after the specified element(s).
The contents of the unqualified list are as follows: #myList# <
ListRest Description Gets a list, without its first element. Returns A copy of list, without the first element. If list has one element, returns an empty list. Category List functions Function syntax ListRest(list [, delimiters ]) See also ListFirst, ListGetAt, ListLast; “Lists” in Chapter 3, “Using ColdFusion Variables,” in ColdFusion MX Developer’s Guide Parameters Parameter Description list A list or a variable that contains one. delimiters A string or a variable that contains one.
ListSetAt Description Replaces the contents of a list element. Returns A copy of a list, with a new value assigned to the element at a specified position. Category List functions Function syntax ListSetAt(list, position, value [, delimiters ]) See also ListDeleteAt, ListGetAt, ListInsertAt; “Lists” in Chapter 3, “Using ColdFusion Variables,” in ColdFusion MX Developer’s Guide History ColdFusion MX: Changed delimiter modification: ColdFusion MX does not modify delimiters in the list.
This is a list of #ListLen(temp)# subjects posted in messages.
ListSort Description Sorts list elements according to a sort type and sort order. Returns A copy of a list, sorted.
Parameter Description sort_order • asc - ascending sort order. Default. - aabzABZ or aAaBbBzzZ, depending on value of sort_type, for letters - from smaller to larger, for numbers • desc - descending sort order. - ZBAzbaa or ZzzBbBaAa, depending on value of sort_type, for letters - from larger to smaller, for numbers delimiters A string or a variable that contains one. Character(s) that separate list elements. The default value is comma.
ListToArray Description Copies the elements of a list to an array. Returns An array Category Array functions, Conversion functions, List functions Function syntax ListToArray(list [, delimiters ]) See also ArrayToList; Chapter 5, “Using Arrays and Structures,” in ColdFusion MX Developer’s Guide Parameters Parameter Description list A list or a variable that contains one. You define a list variable with a cfset statement. delimiters A string or a variable that contains one.
ListValueCount Description Counts instances of a specified value in a list. The search is case-sensitive. Returns The number of instances of value in the list. Category List functions, String functions Function syntax ListValueCount(list, value [, delimiters ]) See also ListValueCountNoCase; “Lists” in Chapter 3, “Using ColdFusion Variables,” in ColdFusion MX Developer’s Guide Parameters Parameter Description list A list or a variable that contains one.
Sales There are no employees in #FORM.
ListValueCountNoCase Description Counts instances of a specified value in a list. The search is case-insensitive. Returns The number of instances of value in the list. Category List functions Function syntax ListValueCountNoCase(list, value [, delimiters ]) See also ListValueCount; “Lists” in Chapter 3, “Using ColdFusion Variables,” in ColdFusion MX Developer’s Guide Parameters Parameter Description list A list or a variable that contains one.
There are no employees in #FORM.
LJustify Description Left justifies characters in a string of a specified length. Returns A copy of a string, left-justified.
Log Description Calculates the natural logarithm of a number. Natural logarithms are based on the constant e (2.71828182845904). Returns The natural logarithm of a number. Category Mathematical functions Function syntax Log(number) See also Exp, Log10 Parameters Parameter Description number Positive real number for which to calculate the natural logarithm Example Log Example Your number, #FORM.number# #FORM.
Log10 Description Calculates the logarithm of number, to base 10. Returns Number; the logarithm of number, to base 10. Category Mathematical functions Function syntax Log10(number) See also Exp, Log Parameters Parameter Description number Positive real number for which to calculate the logarithm Example Log10 Example Your number, #FORM.number# #FORM.number# raised to the E power: #exp(FORM.number)#
LSCurrencyFormat Description Formats a number in a locale-specific currency format. For countries that use the euro, the result depends on the JVM. Returns A formatted currency value.
Currency output The following table shows sample currency output. For locales that use Euro, the Local and International columns contains two entries. The first is entry is the result with a Sun the 1.4.1compliant JVM, the second entry is the result with a 1.3.1-compliant JVM. Locale Type = Local Type = International Type = None Chinese (China) ¥100,000.00 CNY100,000.00 100,000.00 Chinese (Hong Kong) HK$100,000.00 HKD100,000.00 100,000.00 Chinese (Taiwan) NT$100,000.00 TWD100,000.00 100,000.
Locale Type = Local Type = International Type = None Portuguese (Standard) 100.000,00 ¤ R$100.000,00 EUR100.000,00 BRC100.000,00 100.000,00 Spanish (Mexican) $100,000.00 MXN100,000.00 100,000.00 Spanish (Modern) 100.000,00 ¤ 10.000.000 Pts EUR10.000.000 ESP10.000.000 10.000.000 Spanish (Standard) 100.000,00 ¤ 10.000.000 Pts ESP10.000.000 EUR10.000.000 10.000.000 Swedish 100.000,00 kr SEK100.000,00 100.000,00 Note: ColdFusion maps Spanish (Modern) to the Spanish (Standard) format.
LSDateFormat Description Formats the date part of a date/time value in a locale-specific format. Returns A formatted date/time value. If no mask is specified, the value is formatted according to the locale setting of the client computer.
Parameters Parameter Description date A date/time object, in the range 100 AD–9999 AD. mask Characters that show how ColdFusion displays the date: • d: Day of month. Digits; no leading zero for single-digit days • dd: Day of month. Digits; leading zero for single-digit days • ddd: Day of week, abbreviation • dddd: Day of week. Full name • m: Month. Digits; no leading zero for single-digit months • mm: Month. Digits; leading zero for single-digit months • mmm: Month.
LSDateFormat 751
LSEuroCurrencyFormat Description Formats a number in a locale-specific currency format. Returns A formatted currency value. For countries in the Euro currency zone, the function uses the locale’s rule’s for formatting currency in euros.
Currency output The following table shows examples of currency output: Locale Type = Local Type = International Type = None Chinese (China) ¥100,000.00 CNY100,000.00 100,000.00 Chinese (Hong Kong) HK$100,000.00 HKD100,000.00 100,000.00 Chinese (Taiwan) NT$100,000.00 TWD100,000.00 100,000.00 Dutch (Belgian) 100.000,00 ¤ EUR100.000,00 100.000,00 Dutch (Standard) ¤ 100.000,00 EUR100.000,00 100.000,00 English (Australian) $100,000.00 AUD100,000.00 100,000.
The following example shows how the function formats negative values. The format includes a negative sign before the value, or parentheses around the value, according to the formatting rules of the current locale. Input value Output if locale = French (Standard) Output if locale = English (US) -1234.56 -1 234,56 ¤ ($1,234.56) Example LSEuroCurrencyFormat Example LSEuroCurrencyFormat returns a currency value using the locale convention. Default value is "local.
LSIsCurrency Description Determines whether a string is a valid representation of a currency amount in the current locale. Returns True, if the parameter is formatted as a valid currency amount, including the appropriate currency indicator. The return value is True for amounts in the local, international, or none currency formats.
Is the value "#FORM.myValue#" a proper currency value for #GetLocale()#? Answer: #LSIsCurrency(FORM.myValue)#
Is the value "#FORM.myValue#" a proper date value for #GetLocale()#? Answer: #LSIsDate(FORM.myValue)#
LSNumberFormat Description Formats a number in a locale-specific format. Returns A formatted number. • • • • If no mask is specified, it returns the number formatted as an integer If no mask is specified, truncates the decimal part; for example, it truncates 34.57 to 35 If the specified mask cannot correctly mask a number, it returns the number unchanged If the parameter value is "" (an empty string), it returns 0.
Character Meaning 0 Located to the left or right of a mandatory decimal point. Pads with zeros. () If number is less than zero, puts parentheses around the mask. + Puts plus sign before positive number; minus sign before negative number. - Puts space before positive number; minus sign before negative number. , Separates every third decimal place with a comma (or locale-appropriate symbol). L,C Left-justifies or center-justifies number within width of mask column.
An underscore determines whether the code is placed in the far or near position. Most code characters’ effect is determined by the field in which they are located. This example shows how to specify where to put parentheses to display negative numbers: Number Mask Result 3.21 C(__^__) "( 3.21 )" 3.21 C__(^__) " (3.21 )" 3.21 C(__^)__ "( 3.21) " 3.21 C__(^)__ " (3.21) " To set the default display format of date, time, number, and currency values, use the SetLocale function.
LSParseCurrency Description Converts a locale-specific currency string into a formatted number. Attempts conversion by comparing the string with each the three supported currency formats (none, local, international) and using the first that matches. Returns A formatted number (string representation of a number) that matches the value of the parameter.
For a list of the locale-specific formats used to parse the currency, see LSCurrencyFormat. Example LSParseCurrency Example LSParseCurrency coverts a locale-specific currency string to a number. Attempts conversion through each of the three default currency formats. PAGE 765
LSParseDateTime Description Converts a string that is a valid date/time representation in the current locale into a date/time object. Returns A date/time object.
Format Example mmm dd, yyyy h:mm:ss tt Jan 30, 2002 7:02:12 AM mmmm dd, yyyy h:mm:ss tt zzz January 30, 2002 7:02:23 AM PST ddd, mmm dd, yyyy hh:mm:ss Wed, Jan 30, 2002 07:02:12 dddd, mmmm dd, yyyy h:mm:ss tt zzz Wednesday, January 30, 2002 7:02:12 AM PST Valid dates are in the range 100 AD–9999 AD. Two digit years in the range 00-29 are interpreted as being 2000-2029.
LSParseEuroCurrency Description Formats a locale-specific currency string as a number. Attempts conversion through each of the default currency formats (none, local, international). Ensures correct handling of euro currency for Euro zone countries. Returns A formatted number that matches the value of the string.
Current Locale: #locale# Value in local currency: #localCurrency# Parsed using LSParseEuroCurrency: #LSParseEuroCurrency(localCurrency)# Value with International currency formatting: #IntlCurrency# Parsed using LSParseEuroCurrency: #LSParseEuroCurrency(IntlCurrency)# Value with
LSParseNumber Description Converts a string that is a valid numeric representation in the current locale into a formatted number. Returns A formatted number that matches the value of the string.
#LSNumberFormat(1234.5678, "+_________.___")# #LSNumberFormat(1234.5678, "-_________.___")# The actual number: #LSParseNumber(LSNumberFormat(1234.
LSTimeFormat Description Formats the time part of a date/time string into a string in a locale-specific format. Returns A string representing the time value. Category Date and time functions, Display and formatting functions, International functions Function syntax LSTimeFormat(time [, mask ]) See also LSParseDateTime, LSDateFormat, TimeFormat; “Locales” in Chapter 17, “Developing Globalized Applications” in ColdFusion MX Developer’s Guide History ColdFusion MX 6.
Parameters Parameter Description string • A date/time value • A string that is convertible to a time value A date/time object is in the range 100 AD–9999 AD. mask Masking characters that determine the format: • h: Hours; no leading zero for single-digit hours (12-hour clock) • hh: Hours; leading zero for single-digit hours.
#locale# #LSTimeFormat(Now())# #LSTimeFormat(Now(), ‘hh:mm:ss’)# #LSTimeFormat(Now(), ‘hh:mm:sst’)# #LSTimeFormat(Now(), ‘hh:mm:sstt’)# #LSTimeFormat(Now(), ‘HH:mm:ss’)# LSTimeFormat 773
LTrim Description Removes leading spaces from a string. Returns A copy of the string, without leading spaces. Category Display and formatting functions, String functions Function syntax LTrim(string) See also RTrim, ToBase64 Parameters Parameter Description string A string or a variable that contains one Example LTrim Example Your string:"#FORM.myText#" Your string:"#LTrim(FORM.
Max Description Determines the greater of two numbers. Returns The greater of two numbers. Category Mathematical functions Function syntax Max(number1, number2) See also Min Parameters Parameter Description number1, number2 Numbers Example Max Example The maximum of the two numbers is #Max(FORM.myNum1, FORM.myNum2)# The minimum of the two numbers is #Min(FORM.
Mid Description Extracts a substring from a string. Returns A string; the set of characters from string, beginning at start, of length count. Category String functions Function syntax Mid(string, start, count) See also Left, Len, Right Parameters Parameter Description string A string or a variable that contains one. Must be single-quotation mark or doublequotation mark delimited. start A positive integer or a variable that contains one. Position at which to start count.
Minute Description Extracts the minute value from a date/time object. Returns The ordinal value of the minute, in the range 0–59. Category Date and time functions Function syntax Minute(date) See also DatePart, Hash, Second Parameters Parameter Description date • A date/time object, in the range 100 AD–9999 AD. Usage When passing a date/time value as a string, you must enclose it in quotation marks. Otherwise, it is interpreted as a number representation of a date/time object.
Month Description Extracts the month value from a date/time object. Returns The ordinal value of the month, in the range 1 (January) – 12 (December). Category Date and time functions Function syntax Month(date) See also DatePart, MonthAsString, Quarter Parameters Parameter Description date Date/time object, in the range 100 AD–9999 AD. Usage When passing a date/time value as a string, you must enclose it in quotation marks.
MonthAsString Description Determines the name of the month that corresponds to month_number. Returns A string; the name of the specified month, in the current locale. Category Date and time functions, String functions Function syntax MonthAsString(month_number) See also DatePart, Month, Quarter Parameters Parameter Description month_number An integer in the range 1 – 12. Example MonthAsString Example
Now Description Gets the current date and time of the computer running the ColdFusion server. The return value can be passed as a parameter to date functions such as DaysInYear or FirstDayOfMonth. Returns A date/time object; the current date and time of the computer running the ColdFusion server. Category Date and time functions Function syntax Now() See also CreateDateTime, DatePart Example Now Example Now returns the current date and time as a valid date/time object.
NumberFormat Description Creates a custom-formatted number value. Supports the numeric formatting used in the U.S. For international number formatting, see LSNumberFormat. Returns A formatted number value: • If no mask is specified, returns the value as an integer with a thousands separator. • If the parameter value is "" (an empty string), returns 0.
Mask character Meaning , Separates every third decimal place with a comma. L,C Left-justifies or center-justifies number within width of mask column. First character of mask must be L or C. The default value is right-justified. $ Puts a dollar sign before formatted number. First character of mask must be the dollar sign ($). ^ Separates left and right formatting. Note: If you do not specify a sign for the mask, positive and negative numbers do not align in columns.
Number Mask Result 3.21 C(__^)__ "( 3.21) " 3.21 C__(^)__ " (3.21) " When converting from string to double, to prevent rounding errors, this function adds a rounding factor of 1.5543122344752E-014 to the converted number. For example, without adding the rounding factor, converting the string value 1.275 to double with two digits of precision results in a value of 1.27499999999999999, which would be rounded up to 1.27. By adding the rounding factor, the conversion correctly results in a value of 1.
ParagraphFormat Description Replaces characters in a string: • Single newline characters (CR/LF sequences) with spaces • Double newline characters with HTML paragraph tags ( ) Returns A copy of the string, with characters converted.
ParameterExists Description This function is deprecated. Use the IsDefined function. Determines whether a parameter exists. ColdFusion does not evaluate the argument. History ColdFusion MX: Deprecated this function. It might not work, and might cause an error, in later releases.
ParseDateTime Description Parses a date/time string according to the English (U.S.) locale conventions. (To format a date/ time string for other locales, use the LSParseDateTime function.
The expression #DE(form.theTestValue)# is not a valid date
Pi Description Gets the mathematical constant π, accurate to 15 digits. Returns The number 3.14159265358979. Category Mathematical functions Function syntax Pi() See also ASin, Cos, Sin, Tan Example Pi Example The Pi function Returns the number #NumberFormat(Pi(), "_._______________")#, the mathematical constant pi, accurate to 15 digits.
PreserveSingleQuotes Description Prevents ColdFusion from automatically escaping single-quotation mark characters that are contained in a variable. ColdFusion does not evaluate the argument. Returns (None) Category Other functions Function syntax PreserveSingleQuotes(variable) History ColdFusion MX: Changed behavior: ColdFusion automatically escapes simple-variable, arrayvariable, and structure-variable references within a cfquery tag body or block.
You code this function correctly as follows: This function ensures that ColdFusion evaluates the code as follows: '1', '2', '3' Example PreserveSingleQuotes ExampleThis is a useful function for creating lists of information to return from a query.
Quarter Description Calculates the quarter of the year in which a date falls. Returns An integer, 1–4. Category Date and time functions Function syntax Quarter(date) See also DatePart, Month Parameters Parameter Description date A date/time object in the range 100 AD–9999 AD. Usage When passing a date/time value as a string, you must enclose it in quotation marks. Otherwise, it is interpreted as a number representation of a date/time object.
QueryAddColumn Description Adds a column to a query and populates its rows with the contents of a one-dimensional array. Pads query columns, if necessary, to ensure that all columns have the same number of rows. Returns The number of the column that was added.
Usage You can add columns to query objects, such as queries retrieved with the cfquery tag or queries created with the QueryNew function. You cannot use the QueryAddColumn function on a cached query. This function is useful for generating a query object from the arrays of output parameters that Oracle stored procedures can generate. Macromedia recommends that you use the optional datatype parameter.
Health Food | #FastFood# | #FineCuisine# | #HealthFood# | 796 Chapter 3: ColdFusion Functions
QueryAddRow Description Adds a specified number of empty rows to a query. Returns The number of rows in the query Category Query functions Function syntax QueryAddRow(query [, number ]) See also QueryAddColumn, QueryAddRow, QuerySetCell, QueryNew; “Creating a record set with a function” in Chapter 22, “Using Query of Queries,” in ColdFusion MX Developer’s Guide Parameters Parameter Description query Name of an executed query. number Number of rows to add to the query. The default value is 1.
QueryNew Description Creates an empty query (query object). Returns An empty query with a set of named columns, or an empty query. Category Query functions Function syntax QueryNew(columnlist [, columntypelist]) History ColdFusion MX 7: Added columntypelist parameter.
Example The following example uses the QueryNew function to create an empty query with three columns. It populates two rows of the query and displays the contents of the query object and its metadata.
QuerySetCell Description Sets a cell to a value. If no row number is specified, the cell on the last row is set. Returns True, if successful; False, otherwise. Category Query functions Function syntax QuerySetCell(query, column_name, value [, row_number ]) See also QueryAddColumn, QueryAddRow, QueryNew; “Creating a record set with a function” in Chapter 22, “Using Query of Queries,” in ColdFusion MX Developer’s Guide Parameters Parameter Description query Name of an executed query.
QuotedValueList Description Gets the values of each record returned from an executed query. ColdFusion does not evaluate the arguments. Returns A delimited list of the values of each record returned from an executed query. Each value is enclosed in single-quotation marks. Category Query functions, List functions Function syntax QuotedValueList(query.column [, delimiter ]) See also ValueList Parameters Parameter Description query.column Name of an executed query and column.
Rand Description Generates a pseudo-random number. Returns A pseudo-random decimal number, in the range 0 – 1. Category Mathematical functions, Security functions Function syntax Rand([algorithm]) History ColdFusion MX 7: Added the algorithm parameter. See also Randomize, RandRange Parameters Parameter Description algorithm (Optional) The algorithm to use to generated the random number.
Randomize Description Seeds the pseudo-random number generator with an integer number, ensuring repeatable number patterns. Returns A pseudo-random decimal number, in the range 0–1. Category Mathematical functions, Security functions Function syntax Randomize(number[, algorithm]) History ColdFusion MX 7: Added the algorithm parameter. See also Rand, RandRange Parameters Parameter Description number Integer number.
Example The following example calls the Randomize function to seed the random number generator and generates 10 random numbers. To show the effect of the seed, submit the form with the same value multiple times. Randomize Example Seed value is #FORM.
RandRange Description Generates a pseudo-random integer in the range between two specified numbers. Returns A pseudo-random integer. Category Mathematical functions, Security functions Function syntax RandRange(number1, number2[, algorithm]) History ColdFusion MX 7: Added the algorithm parameter. See also Rand, Randomize Parameters Parameter Description number1, number2 Integer numbers. If the numbers are not in the range -2,147,483,648 – 2,147,483,647, ColdFusion generates an error.
Example The following example contains a form that requires random number range values, and lets you optionally specify a random number seed value. It uses cfform controls and attributes to specify a default range, ensure that the range fields have values, and validate that the field values are in a specified integer range. When you submit the form, it checks whether the seed field has an empty string; if the field has a value, the code uses the number to seed the random number generator.
REFind Description Uses a regular expression (RE) to search a string for a pattern. The search is case sensitive. For more information on regular expressions, including escape sequences, anchors, and modifiers, see Chapter 7, “Using Regular Expressions in Functions,” in ColdFusion MX Developer’s Guide.
Parameter Description start Optional. A positive integer, or a variable that contains one. Position in the string at which to start search. The default value is 1. returnsubexpressions Optional. Boolean. Whether to return substrings of reg_expression, in arrays named len and pos: • True: if the regular expression is found, the first array element contains the length and position, respectively, of the first match.
The first call to REFind to search this string is: REFind("[A-Za-z]+",testString,1,"TRUE") This function returns a structure that contains two arrays: pos and len. To create this structure you can use a CFSET statement, for example: <CFSET st = REFind("[[:alpha:]]",testString,1,"TRUE")> The number of elements in each array: #ArrayLen(st.pos)#.
REFindNoCase Description Uses a regular expression (RE) to search a string for a pattern, starting from a specified position. The search is case-insensitive. For more information on regular expressions, including escape sequences, anchors, and modifiers, see Chapter 7, “Using Regular Expressions in Functions,” in ColdFusion MX Developer’s Guide.
Parameter Description start Optional. A positive integer or a variable that contains one. Position at which to start search. The default value is 1. returnsubexpressions Optional. Boolean. Whether to return substrings of reg_expression, in arrays named len and pos: • True: if the regular expression is found, the first array element contains the length and position, respectively, of the first match.
The first call to REFindNoCase to search this string is: REFindNoCase("[[:alpha:]]+",testString,1,"True") This function returns a structure that contains two arrays: pos and len. To create this structure you can use a CFSET statement, for example: <CFSET st = REFindNoCase("[[:alpha:]]+",testString,1,"True")> The number of elements in each array: #ArrayLen(st.pos)#.
ReleaseComObject Description Releases a COM Object and frees up resources that it used. Returns Nothing. Category Extensibility functions Function syntax ReleaseComObject(objectName) See also CreateObject, cfobject History ColdFusion MX 6.1: Added this function. Parameters Parameter Description objectName Variable name of a COM object that was created using the CreateObject function or cfobject tag.
RemoveChars Description Removes characters from a string. Returns A copy of the string, with count characters removed from the specified start position. If no characters are found, returns zero. Category String functions Function syntax RemoveChars(string, start, count) See also Insert, Len Parameters Parameter Description string A string or a variable that contains one. String in which to search. start A positive integer or a variable that contains one. Position at which to start search.
RepeatString Description Creates a string that contains a specified number of repetitions of the specified string. Returns A string. Category String functions Function syntax RepeatString(string, count) See also CJustify, LJustify, RJustify Parameters Parameter Description string A string or a variable that contains one. count Number of repeats. Example RepeatString Example RepeatString returns a string created from string, repeated a specified number of times.
Replace Description Replaces occurrences of substring1 in a string with substring2, in a specified scope. The search is case-sensitive. Returns The string, after making replacements. Category String functions Function syntax Replace(string, substring1, substring2 [, scope ]) See also Find, REFind, ReplaceNoCase, ReplaceList, REReplace Parameters Parameter Description string A string or a variable that contains one. String in which to search. substring1 A string or a variable that contains one.
ReplaceList Description Replaces occurrences of the elements from a delimited list in a string with corresponding elements from another delimited list. The search is case-sensitive. Returns A copy of the string, after making replacements.
Replacelist Example Two PAGE 819
ReplaceNoCase Description Replaces occurrences of substring1 with substring2, in the specified scope. The search is caseinsensitive. Returns A copy of the string, after making replacements. Category String functions Function syntax ReplaceNoCase(string, substring1, substring2 [, scope ]) See also Find, REFind, Replace, ReplaceList, REReplace Parameters Parameter Description string A string (or variable that contains one) within which to replace substring.
REReplace Description Uses a regular expression (RE) to search a string for a string pattern and replace it with another. The search is case-sensitive. Returns If the scope parameter is set to one, returns a string with the first occurrence of the regular expression replaced by the value of substring. If the scope parameter is set to all, returns a string with all occurrences of the regular expression replaced by the value of substring.
Usage For details on using regular expressions, see Chapter 7, “Using Regular Expressions in Functions,” in ColdFusion MX Developer’s Guide. Example The REReplace function returns string with a regular expression replaced with substring in the specified scope. Case-sensitive search.
REReplaceNoCase Description Uses a regular expression to search a string for a string pattern and replace it with another. The search is case-insensitive. Returns • If scope = "one": returns a string with the first occurrence of the regular expression replaced by the value of substring. • If scope = "all": returns a string with all occurrences of the regular expression replaced by the value of substring. • If the function finds no matches: returns a copy of the string, unchanged.
#REReplaceNoCase("cabaret","C|B","G","ALL")# REReplaceNoCase("cabaret","[A-Z]","G","ALL"): #REReplaceNoCase("cabaret","[A-Z]","G","ALL")# REReplaceNoCase("I LOVE JELLIES","jell(y|ies)","cookies"): #REReplaceNoCase("I LOVE JELLIES","jell(y|ies)","cookies")# REReplaceNoCase("I LOVE JELLY","jell(y|ies)","cookies"): #REReplaceNoCase("I LOVE JELLY","jell(y|ies)","cookies")# REReplaceNoCase 823
Reverse Description Reverses the order of items, such as the characters in a string, the digits in a number, or the elements in an array. Returns A copy of string, with the characters in reverse order.
Right Description Gets a specified number of characters from a string, beginning at the right. Returns the specified number of characters from the end (or right side) of the specified string.
Please enter a string of more than 0 (zero) characters.
Round Description Rounds a number to the closest integer that is larger than the input parameter. Returns An integer. Category Mathematical functions Function syntax Round(number) See also Ceiling, Fix, Int Parameters Parameter Description number Number to round Usage Use this function to round a number. This function rounds numbers that end with .5 up to the nearest integer. It rounds 3.5 to 4 and -3.5 to -3. Example Round Example This function rounds a number to the closest integer.
RTrim Description Removes spaces from the end of a string. Returns A copy of string, after removing trailing spaces. Category String functions Function syntax RTrim(string) See also LTrim, Trim Parameters Parameter Description string A string or a variable that contains one Example RTrim Example Your string:"#FORM.myText#" Your string:"#RTrim(FORM.myText)#" (right trimmed)
SendGatewayMessage Description Sends an outgoing message through a ColdFusion MX event gateway. Returns String. The value returned depends on the gateway type.
Gateway type Return values SMS If the gateway is in asynchronous mode, returns the empty string immediately. If the gateway is in synchronous mode, the function waits for the gateway to return a response. If the message was succesfully sent to the short message service center (SMSC), returns the message ID from the SMSC. If an error occured, returns a string indicating the cause. XMPP If the message or command was successful, returns OK If an error occured, returns a string indicating the cause.
SetEncoding Description Sets the character encoding (character set) of Form and URL scope variable values; used when the character encoding of the input to a form, or the character encoding of a URL, is not in UTF-8 encoding.
Usage Use this function when the character encoding of the input to a form or the character encoding of a URL is not in UTF-8 encoding. For example, Traditional Chinese characters are often in Big5 encoding. This function resets URL and Form variables, so you should call it before using these variables (typically, in the Application.cfm page or Application.cfc file). Calling this function first also avoids interpreting the characters of the variables incorrectly.
SetLocale Description Sets the country/language locale for ColdFusion processing and the page returned to the client. The locale value determines the default format of date, time, number, and currency values, according to language and regional conventions. Returns The locale value prior to setting the new locale, as a string.
Chinese (Taiwan) French (Standard) Norwegian (Nynorsk) Dutch (Belgian) French (Swiss) Portuguese (Brazilian) Dutch (Standard) German (Austrian) Portuguese (Standard) English (Australian) German (Standard) Spanish (Modern) English (Canadian) German (Swiss) Spanish (Standard) English (New Zealand) Italian (Standard) Swedish English (UK) Italian (Swiss) English (US) Japanese ColdFusion determines the locale value as follows: • By default, ColdFusion uses the JVM locale, and the default J
SetProfileString Description Sets the value of a profile entry in an initialization file. Returns An empty string, upon successful execution; otherwise, an error message.
Timeout value should be greater than zero in order to provide time for user response. The timeout value in your initialization file is already #MyTimeout#. Boot Loader Timeout is set to: #timeout#.
SetVariable Description This function is no longer required in well-formed ColdFusion pages. Sets a variable in the name parameter to the value of the value parameter. Returns The new value of the variable.
Your variable, #varName# The value of #varName# is #varNameValue# 840 Chapter 3: ColdFusion Functions
Sgn Description Determines the sign of a number. Returns • 1, if number is positive. • 0, if number is 0. • -1, if number is negative. Category Mathematical functions Function syntax Sgn(number) See also Abs Parameters Parameter Description number A number Example Sgn Example Sgn determines the sign of a number. Returns 1 if number is positive; 0 if number is 0; -1 if number is negative. Sgn(14): #Sgn(14)# Sgn(21-21): #Sgn(21-21)# Sgn(-0.
Sin Description Calculates the sine of an angle that is entered in radians. Returns A number; the sine of the angle. Category Mathematical functions Function syntax Sin(number) See also ASin, Cos, ACos, Tan, Atn, Pi Parameters Parameter Description number Angle, in radians for which to calculate the sine. Usage The range of the result is -1 to 1. To convert degrees to radians, multiply degrees by π/180. To convert radians to degrees, multiply radians by 180/π.
SpanIncluding Description Gets characters from a string, from the beginning to a character that is not in a specified set of characters. The search is case-sensitive. Returns A string; characters from string, from the beginning to a character that is not in set.
Sqr Description Calculates the square root of a number. Returns Number; square root of number. Category Mathematical functions Function syntax Sqr(number) See also Abs Parameters Parameter Description number A positive integer or a variable that contains one. Number whose square root to get. Usage The value in number must be greater than or equal to 0. Example Sqr Example Returns the square root of a positive number.
StripCR Description Deletes return characters from a string. Returns A copy of string, after removing return characters. Category Display and formatting functions, String functions Function syntax StripCR(string) See also ParagraphFormat Parameters Parameter Description string A string or a variable that contains one Usage Useful for preformatted (between and tags) HTML display of data entered in textarea fields.
StructAppend Description Appends one structure to another. Returns True, upon successful completion; False, otherwise. Category Structure functions Function syntax StructAppend(struct1, struct2, overwriteFlag) See also Structure functions; “Modifying a ColdFusion XML object” in Chapter 35, “Using XML and WDDX,” in ColdFusion MX Developer’s Guide History ColdFusion MX: Changed behavior: this function can be used on XML objects.
StructClear Description Removes all data from a structure. Returns True, on successful execution; False, otherwise. Category Structure functions Function syntax StructClear(structure) See also Structure functions; “Modifying a ColdFusion XML object” in Chapter 35, “Using XML and WDDX,” in ColdFusion MX Developer’s Guide History ColdFusion MX: Changed behavior: this function can be used on XML objects.
StructInsert(employee, "lastname", Form.lastname); StructInsert(employee, "email", Form.email); StructInsert(employee, "phone", Form.phone); StructInsert(employee, "department", Form.
StructCopy Description Copies a structure. Copies top-level keys, values, and arrays in the structure by value; copies nested structures by reference. Returns A copy of a structure, with the same keys and values; if structure does not exist, throws an exception.
The following table shows how variables are assigned: Variable type Assigned by structure.any_simple_value Boolean Binary Base64 Value structure.array Value structure.nested_structure Reference structure.object Reference structure.query Reference Example // This script creates a structure that StructCopy copies by value. // Create elements. s = StructNew(); s.
Modified Original Values // Simple values s.number = #s.number# s.string = #s.string# // Array value s.array[1][1] = #s.array[1][1]# s.array[1][2] = #s.array[1][2]# Copied structure values should be the same as the original. // Simple values copied.number = #copied.number# copied.string = #copied.string# // Array value copied.array[1][1] = #copied.array[1][1]# copied.array[1][2] = #copied.
s.nested.number = 100; s.nested.string = "hello tommy (modified)"; s.nested.array[1][1] = "one one (modified)"; s.nested.array[1][2] = "one two (modified)"; Modified Original Values // Simple values s.nested.number = #s.nested.number# s.nested.string = #s.nested.string# // Array value s.nested.array[1][1] = #s.nested.array[1][1]# s.nested.array[1][2] = #s.nested.
StructCount Description Counts the keys in a structure. Returns A number; if structure does not exist, throws an exception. Category Structure functions Function syntax StructCount(structure) See also Structure functions; “Modifying a ColdFusion XML object” in Chapter 35, “Using XML and WDDX,” in ColdFusion MX Developer’s Guide History ColdFusion MX: Changed behavior: this function can be used on XML objects.
Employee Add Complete #StructCount(attributes.EMPINFO)# columns added.
StructDelete Description Removes an element from a structure. Returns Boolean value. The value depends on the indicatenotexisting parameter value. Category Structure functions Function syntax StructDelete(structure, key [, indicatenotexisting ]) See also Structure functions; “Modifying a ColdFusion XML object” in Chapter 35, “Using XML and WDDX,” in ColdFusion MX Developer’s Guide History ColdFusion MX: Changed behavior: this function can be used on XML objects.
StructInsert(employee, "phone", phone); StructInsert(employee, "department", department); Before deletion, employee structure looks like this: Did I delete the field "#form.field#"? The code indicates: #rc# The structure now looks like this:
Employee Add Complete ---> StructFind 861
StructFindKey Description Searches recursively through a substructure of nested arrays, structures, and other elements, for structures whose values match the search key in the value parameter. Returns An array that contains structures with values that match value.
StructFindValue Description Searches recursively through a substructure of nested arrays, structures, and other elements for structures with values that match the search key in the value parameter. Returns An array that contains structures with values that match the search key value. If none are found, returns an array of size 0.
StructGet Description Gets a structure(s) from a specified path. Returns An alias to the variable in the pathDesired parameter. If necessary, StructGet creates structures or arrays to make pathDesired a valid variable "path.
Dog.Myscope.Test.Foo is not defined #dog.myscope.test.foo# #request.myscope[1].test.foo# #request.myscope[1].test[2].
StructInsert Description Inserts a key-value pair into a structure. Returns True, upon successful completion. If structure does not exist, or if key exists and allowoverwrite = "False", ColdFusion throws an exception.
StructInsert(employee, StructInsert(employee, StructInsert(employee, StructInsert(employee, "lastname", FORM.lastname); "email", FORM.email); "phone", FORM.phone); "department", FORM.
StructIsEmpty Description Determines whether a structure contains data. Returns True, if structure is empty; if structure does not exist, ColdFusion throws an exception. Category Decision functions, Structure functions Function syntax StructIsEmpty(structure) See also Structure functions; “Modifying a ColdFusion XML object” in Chapter 35, “Using XML and WDDX,” in ColdFusion MX Developer’s Guide History ColdFusion MX: Changed behavior: this function can be used on XML objects.
Employee Add Complete StructIsEmpty 869
StructKeyArray Description Finds the keys in a ColdFusion structure. Returns An array of keys; if structure does not exist, ColdFusion throws an exception. Category Structure functions Function syntax StructKeyArray(structure) See also Structure functions; “Modifying a ColdFusion XML object” in Chapter 35, “Using XML and WDDX,” in ColdFusion MX Developer’s Guide Parameters Parameter Description structure Structure from which to extract a list of keys Usage A structure’s keys are unordered.
StructKeyList Description Extracts keys from a ColdFusion structure. Returns A list of keys; if structure does not exist, ColdFusion throws an exception. Category Structure functions Function syntax StructKeyList(structure [, delimiter]) See also Structure functions; “Modifying a ColdFusion XML object” in Chapter 35, “Using XML and WDDX,” in ColdFusion MX Developer’s Guide Parameters Parameter Description structure Structure from which to extract a list of keys. delimiter Optional.
StructKeyList Function Listing the Keys in the Employees Structure This example uses StructNew function to create structure "employee" that supplies employee information. The fields are filled with the contents of the following form. After you enter employee information into structure, example uses StructKeyList function to list keys in structure. This code does not show how to insert information into a database.
StructNew Description Creates a structure. Returns A structure. Category Structure functions Function syntax StructNew() See also Structure functions; “Structure functions” in Chapter 5, “Using Arrays and Structures,” in ColdFusion MX Developer’s Guide Parameters None Example Add New Employees PAGE 876
StructSort Description Returns a sorted array of the top level keys in a structure. Sorts using alphabetic or numeric sorting, and can sort based on the values of any structure element. Returns An array of top-level key names (strings), sorted by the value of the specified subelement.
employee = StructNew() ; employee["salary"] = salary ; // employee.salary = salary ; employees["employee#i#"] = employee ; departments["department#i#"] = StructNew() ; departments["department#i#"].
StructUpdate Description Updates a key with a value. Returns True, on successful execution; if the structure does not exist, ColdFusion throws an error. Category Structure functions Function syntax StructUpdate(structure, key, value) See also Structure functions; “Modifying a ColdFusion XML object” in Chapter 35, “Using XML and WDDX,” in ColdFusion MX Developer’s Guide History ColdFusion MX: Changed behavior: this function can be used on XML objects.
Tan Description Calculates the tangent of an angle that is entered in radians. Returns A number; the tangent of an angle. Category Mathematical functions Function syntax Tan(number) See also Atn, Cos, ACos, Sin, ASin, Pi Parameters Parameter Description number Angle, in radians, for which to calculate the tangent. Usage To convert degrees to radians, multiply degrees by π/180. To convert radians to degrees, multiply radians by 180/π.
Parameters Parameter Description time A date/time value or string to convert mask Masking characters that determine the format: • h: hours; no leading zero for single-digit hours (12-hour clock) • hh: hours; leading zero for single-digit hours (12-hour clock) • H: hours; no leading zero for single-digit hours (24-hour clock) • HH: hours; leading zero for single-digit hours (24-hour clock) • m: minutes; no leading zero for single-digit minutes • mm: minutes; a leading zero for single-digit minutes • s:
TimeFormat function.
ToBase64 Description Calculates the Base64 representation of a string or binary object. The Base64 format uses printable characters, allowing binary data to be sent in forms and e-mail, and stored in a database or file. Returns The Base64 representation of a string or binary object.
Usage Macromedia recommends that you use the BinaryEncode function to convert binary data to Base64-encoded data in all new applications. ToBase64 Example The following string is the concatenation of all characters (32 to 255) from the ASCII table.
ToBinary Description Calculates the binary representation of Base64-encoded data. Returns The binary representation of Base64-encoded data.
Base64 representation of binary data is identical to the Base64 representation of string data. Conversion error.
ToScript Description Creates a JavaScript or ActionScript expression that assigns the value of a ColdFusion variable to a JavaScript or ActionScript variable. This function can convert ColdFusion strings, numbers, arrays, structures, and queries to JavaScript or ActionScript syntax that defines equivalent variables and values. Returns A string that contains a JavaScript or ActionScript variable definition corresponding to the specified ColdFusion variable value.
Usage To use a ColdFusion variable in JavaScript or ActionScript, the ToScript function must be in a cfoutput region and be surrounded by number signs (#).
An ActionScript-style array does not require you to include the wddx.js file, and creates a variable that you can use in ActionScript on a Flash format form, for example, in an onChange attribute. If the outputformat parameter is False, setting ASFormat to True causes ToScript to use the ActionScript shortcut [] in place of New Array() and the shortcut {} in place of New Object(). Using these shortcuts allows you to pass ActionScript into cfform attributes without triggering ActionScript validation.
{ document.write("myArray[" + i + "]: " + jsArray[i] + " "); } Converting a query This section converts the following query object to both WDDX format and ActionScript type Javascript objects.
ToString Description Converts a value to a string. Returns A string. Category Conversion functions, String functions Function syntax ToString(value[, encoding]) See also ToBase64, ToBinary, CharsetEncode; Chapter 35, “Using XML and WDDX,” in ColdFusion MX Developer’s Guide History ColdFusion MX: • Changed Unicode support: ColdFusion supports the Java UCS-2 representation of Unicode character values 0–65535. (ColdFusion 5 and earlier releases supported ASCII values 1–255.
Parameters Parameter Description value Value to convert to a string; can be a simple value such as an integer, a binary object, or an XML document object. encoding The character encoding (character set) of the string. Optional for binary data, Generates an error if used for a simple value or XML document object.
The following is the string representation of the binary data.
Trim Description Removes leading and trailing spaces from a string. Returns A copy of string, after removing leading and trailing spaces. Category String functions Function syntax Trim(string) See also LTrim, RTrim Parameters Parameter Description string A string or a variable that contains one Example Trim Example Your string:"#FORM.myText#" Your string:"#Trim(FORM.
UCase Description Converts the alphabetic characters in a string to uppercase. Returns A copy of a string, converted to uppercase. Category String functions Function syntax UCase(string) See also LCase Parameters Parameter Description string A string or a variable that contains one Example UCase Example Your text, #FORM.sampleText#, returned in uppercase is #UCase(FORM.
URLDecode Description Decodes a URL-encoded string. Returns A copy of a string, decoded. Category Conversion functions, Other functions, String functions Function syntax URLDecode(urlEncodedString[, charset]) See also URLEncodedFormat; “Tags and functions for globalizing” in Chapter 17, “Developing Globalized Applications,” in ColdFusion MX Developer’s Guide ColdFusion MX 6.1: Changed the default charset: the default charset is the character encoding of the URL scope.
Usage URL encoding formats some characters with a percent sign and the two-character hexadecimal representation of the character. For example, a character whose code is 129 is encoded as %81. A space is encoded with a plus sign. Query strings in HTTP are always URL-encoded.
URLEncodedFormat Description Generates a URL-encoded string. For example, it replaces spaces with %20, and nonalphanumeric characters with equivalent hexadecimal escape sequences. Passes arbitrary strings within a URL (ColdFusion automatically decodes URL parameters that are passed to a page). Returns A copy of a string, URL-encoded.
Usage URL encoding formats some characters with a percent sign and the two-character hexadecimal representation of the character. For example, a character whose code is 129 is encoded as %81. A space is encoded with a plus sign. Query strings in HTTP are always URL-encoded. Example URLEncodedFormat Example The url variable url.myExample was passed from the previous link ... its value is: "#url.
URLSessionFormat Description Depending on whether a client computer accepts cookies, this function does the following: • If the client does not accept cookies: automatically appends all required client identification information to a URL • If the client accepts cookies: does not append information This function automatically determines which identifiers are required, and sends only the required information.
Val Description Converts numeric characters that occur at the beginning of a string to a number. Returns A number. If conversion fails, returns zero. Category Conversion functions, String functions Function syntax Val(string) See also IsNumeric Parameters Parameter Description string A string or a variable that contains one Usage This function works as follows: • • • • If TestValue = "234A56?7'", Val(TestValue) returns 234. If TestValue = "234'5678'9?'", Val(TestValue) returns 234.
value = "Is the beginning numeric?" name = ""> Val 903
ValueList Description Inserts a delimiter between each value in an executed query. ColdFusion does not evaluate the arguments. Returns A delimited list of the values of each record returned from an executed query. Category List functions, Query functions Function syntax ValueList(query.column [, delimiter ]) See also QuotedValueList Parameters Parameter Description query.column Name of an executed query and column. Separate query name and column name with a period.
Week Description From a date/time object, determines the week number within the year. Returns An integer in the range 1–53; the ordinal of the week, within the year. Category Date and time functions Function syntax Week(date) See also DatePart Parameters Parameter Description date A date/time object in the range 100 AD–9999 AD. Usage When passing date as a string, enclose it in quotation marks. Otherwise, it is interpreted as a number representation of a date.
Wrap Description Wraps text so that each line has a specified maximum number of characters. Returns String containing the wrapped text. Category String functions Function syntax Wrap(string, limit[, strip]) See also cfmail History ColdFusion MX 6.1: Added this function Parameters Parameter Description string String or variable that contains one. The text to wrap. limit Positive integer maximum number of characters to allow on a line.
WriteOutput Description Appends text to the page-output stream. This function writes to the page-output stream regardless of conditions established by the cfsetting tag. Category Other functions, System functions Function syntax WriteOutput(string) Parameters Parameter Description string A string or a variable that contains one Usage Within the cfquery and cfmail tags, this function does not output to the current page; it writes to the current SQL statement or mail text.
XmlChildPos Description Gets the position of a child element within an XML document object. Returns The position, in an XmlChildren array, of the Nth child that has the specified name. Category XML functions Function syntax XmlChildPos(elem, childName, N) See also IsXmlElem, XmlElemNew, XmlSearch, XmlTransform; Chapter 35, “Using XML and WDDX” in ColdFusion MX Developer’s Guide History ColdFusion MX: Added this function. Parameters Parameter Description elem XML element within which to search.
Laura Ingalls elempos=XMLChildPos(xmlobject.employee.name[1], "Status", 2); ArrayDeleteAt(xmlobject.employee.name[1].
XmlElemNew Description Creates an XML document object element. Returns An XML document object element. Category XML functions Function syntax XmlElemNew(xmlObj[, namespace], childName) See also cfxml, IsXmlElem, XmlChildPos, XmlFormat, XmlNew, XmlParse; Chapter 35, “Using XML and WDDX” in ColdFusion MX Developer’s Guide History ColdFusion MX 7: Added the namespace parameter. ColdFusion MX: Added this function.
else MyDoc.MyRoot.XmlText = "The value of testVar is False."; for (i = 1; i LTE 4; i = i + 1) { MyDoc.MyRoot.XmlChildren[i] = XmlElemNew(MyDoc,"childNode"); MyDoc.MyRoot.XmlChildren[i].XmlText = "This is Child node " & i &".
XmlFormat Description Escapes special XML characters in a string so that the string can be used as text in XML. Returns A copy of the string parameter that is safe to use as text in XML. Category String functions, XML functions Function syntax XmlFormat(string) See also cfxml, XmlNew, XmlParse, XmlValidate; Chapter 35, “Using XML and WDDX” in ColdFusion MX Developer’s Guide History ColdFusion MX: Added this function.
#XmlFormat("Body of element with <, >, "" and & goes here.
XmlGetNodeType Description Determines the type of an XML document object node. Returns A string identifying the XML node type. The following values are valid: ATTRIBUTE_NODE CDATA_SECTION_NODE COMMENT_NODE DOCUMENT_FRAGMENT_NODE DOCUMENT_NODE DOCUMENT_TYPE_NODE ELEMENT_NODE ENTITY_NODE ENTITY_REFERENCE_NODE NOTATION_NODE PROCESSING_INSTRUCTION_NODE TEXT_NODE If the argument is not a document object node, the function generates an error.
- Imported from France 1 15.95
Node Types xmlobject: #XMLGetNodeType(xmlobject)# xmlobject.order: #XMLGetNodeType(xmlobject.order)# Now check the types of all the nodes in the xmlobject.order.items.item element’s XmlNodes array.
XmlNew Description Creates an XML document object. Returns An empty XML document object. Category XML functions Function syntax XmlNew([caseSensitive]) See also cfxml, IsXmlDoc, ToString, XmlFormat, XmlParse, XmlValidate; Chapter 35, “Using XML and WDDX” in ColdFusion MX Developer’s Guide History ColdFusion MX: Added this function.
Example The following example creates and displays a ColdFusion document object: MyDoc = XmlNew(); MyDoc.xmlRoot = XmlElemNew(MyDoc,"MyRoot"); if (testVar IS TRUE) MyDoc.MyRoot.XmlText = "The value of testVar is True."; else MyDoc.MyRoot.XmlText = "The value of testVar is False."; for (i = 1; i LTE 4; i = i + 1){ MyDoc.MyRoot.XmlChildren[i] = XmlElemNew(MyDoc,"childNode"); MyDoc.MyRoot.XmlChildren[i].XmlText = "This is Child node " & i &".
XmlParse Description Converts XML text into an XML document object. Returns An XML document object. Category Conversion functions, XML functions Function syntax XmlParse(xmlText [[, caseSensitive ], validator]) See also cfxml, IsXML, ToString, XmlFormat, XmlNew, XmlSearch, XmlTransform, XmlValidate; Chapter 35, “Using XML and WDDX” in ColdFusion MX Developer’s Guide History ColdFusion MX 7: • Added the validator parameter. • Added support for filenames and URLs in the xmlText parameter.
The caseSensitive parameter value determines whether identifiers whose characters are of varying case, but are otherwise the same, refer to different components; for example: • If true, the element or attribute names “name” and “NAME” refer to different elements or attributes. • If false, these names refer to the same elements or attributes. If your XML object is case sensitive, you cannot use dot notation to reference an element or attribute name.
Standard paint thinner 3 8.95 The custorder.
XmlSearch Description Uses an XPath language expression to search an XML document object. Returns An array of XML object nodes that match the search criteria. Category XML functions Function syntax XmlSearch(xmlDoc, xPathString) See also cfxml, IsXML, XmlChildPos, XmlParse, XmlTransform; Chapter 35, “Using XML and WDDX” in ColdFusion MX Developer’s Guide History ColdFusion MX 7: Added support for attribute searches. ColdFusion MX: Added this function.
Laura Ingalls The CFML file contains the following lines: myxmldoc = XmlParse("C:\CFusionMX7\wwwroot\examples\employeesimple.xml"); selectedElements = XmlSearch(myxmldoc, "/employee/name/last"); for (i = 1; i LTE ArrayLen(selectedElements); i = i + 1) writeoutput(selectedElements[i].
XmlTransform Description Applies an Extensible Stylesheet Language Transformation (XSLT) to XML. The XML can be in string format or an XML document object. Returns A string containing the results of applying the XSLT to the XML.
If the XSLT code contains include statements with relative paths, ColdFusion resolves them relative to the location of the XSLT file, or for an XSL string, the location of the current ColdFusion page. Example The following example converts an XML document that represents a customer order into an HTML document with the customer name and a table with the order items and quantities: The custorder.xml file that represents a customer order has the following lines:
|
The CFML file has the following lines: