Name
String.concat( ) Method — combine one or more values into a single string
Availability
Flash 5
Synopsis
string.concat(value1, value2,...valuen)
Arguments
- value1,...value
n
Values to be converted to strings (if necessary) and concatenated with
string
.
Returns
The result of concatenating string
with
value1
, value2
,
...valuen
.
Description
The concat( )
method creates a string from a
series of values. It is equivalent to using the concatenation
operator (+
) with strings but is sometimes
preferred for clarity, as the +
operator can also
be used to add numbers. For details on concat(
)
, see Chapter 4.
Usage
Note that concat( )
does not modify
string
; it returns a completely new
string.
Example
var greeting = "Hello";
excitedGreeting = greeting.concat("!");
trace(greeting); // Displays: "Hello"
trace(excitedGreeting); // Displays: "Hello!"
var x = 4; // Initialize x
as an integer
trace(x + 5); // Displays: 9
trace(x.concat(5)); // Fails because x is not a string.
trace(String(x).concat(5)); // Displays: "45"
var x = "4"; // Initialize x as a string
trace(x.concat(5)); // Displays: "45"
trace(concat("foo", "fee")); // Fails because concat( ) must be invoked
// as a method of a string.
See Also
The +
operator, in Chapter 5,
Section 4.6.1.1 in Chapter 4
Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.