11.6. WMLScript String Operators - Concatenating Strings

The + operator has two uses in WMLScript. One use is to calculate the addition result of two numbers. We have seen how to do this earlier. Another use is to concatenate two strings. If both operands are numeric values, the + operator will act as the addition operator; if any one of the operands is a string, the + operator will act as the string concatenation operator. For example:

x = 1 + 1;
y = 1 + "1";

After executing the above script, x has the integral value 2 and y has the string value "11".

Like the + operator, the += operator can also be used for both addition and string concatenation. The script below demonstrates its use:

var z = "WML Tutorial and ";
z += "WMLScript Tutorial";

After executing the above script, z contains the string "WML Tutorial and WMLScript Tutorial". The above script is equivalent to the one below:

var z = "WML Tutorial and ";
z = z + "WMLScript Tutorial";

Previous Page Page 23 of 71 Next Page

Feedback Form (ExpandCollapse)

What do you think about this web page?

(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.