Table of Contents

String.concat( ) Method Flash 5

combine one or more values into a single string
string.concat(value1, value2,...valuen)

Arguments

value1,...valuen

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

Section 4.6.1 and Section 4.6.1.1; Section 5.3.1


Table of Contents