May 2001
Intermediate to advanced
720 pages
23h 24m
English
String.concat( ) Method — combine one or more values into a single string
Flash 5
string.concat(value1, value2,...valuen)
n
Values to be converted to strings (if necessary) and concatenated
with string.
The result of concatenating string with
value1, value2,
...valuen.
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.
Note that concat( ) does not modify
string; it returns a completely new
string.
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.The + operator, in Chapter 5,
Section 4.6.1.1 in Chapter 4
Read now
Unlock full access