Whatterz


Using JavaScript String Operators in ColdFusion 8

by Simon. Average Reading Time: less than a minute.

In addition to the comparison operators, which can be used on string values, the concatenation operator (&) concatenates two string values together, returning another string that is the union of the two operand strings. For example, “my ” & “string” returns the string “my string”.

The shorthand assignment operator &= can also be used to concatenate strings. For example, if the variable mystring has the value “alpha”, then the expression mystring &= “bet” evaluates to “alphabet” and assigns this value to mystring. This expression can be used in all CFML expressions.

<cfscript>
mystring = "Alpha";
mystring &= "bet";
</cfscript>
 
<cfdump var="#variables#" label="Concatenating Strings" />

This returns the following output:

Concatenating Strings Operator Example

This article has been tagged

, , , , , ,

Other articles I recommend

Using JavaScript Comparison Operators in ColdFusion 8

Following on from the first three parts of the “Using JavaScript Operators” in ColdFusion 8, where I introduced Arithmetic, Assignment and Logical Operators, it is now the turn of Comparison Operators.

Using JavaScript Assignment Operators in ColdFusion 8

In my first post in this series, I introduced Using JavaScript Arithmetic Operators in ColdFusion 8. Now we’ll concentrate on Assignment operators.

An assignment operator assigns a value to its left operand based on the value of its right operand.

The basic assignment operator is equal (=), which assigns the value of its right operand to its left operand. That is, x = y assigns the value of y to x. The other assignment operators are usually shorthand for standard operations, as shown in the following table.

Using JavaScript Arithmetic Operators in ColdFusion 8

An often mentioned complaint by ColdFusion developers is the lack of operators commonly found in other programming languages such as JavaScript. For example, instead of the greater-than (>) symbol we have been restricted to the more wordy GT or GREATER THAN operator. However, in ColdFusion 8 this has changed and we have more freedom to use familiar JavaScript operators in <cfscript> blocks.

In the following series of posts, I will introduce the changes and show some simple examples. The first in the series is Arithmetic Operators.

Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value. The standard arithmetic operators are addition (+), subtraction (-), multiplication (*), and division (/).

These operators work as they do in most other programming languages.