& (operator)

Syntax

expression1 & expression2

Description

Returns the concatenation of expression1 and expression2.

Comments

If both expressions are strings, then the type of the result is String. Otherwise, the type of the result is a String variant.

When nonstring expressions are encountered, each expression is converted to a String variant. If both expressions are Null, then a Null variant is returned. If only one expression is Null, then it is treated as a zero-length string. Empty variants are also treated as zero-length strings.

In many instances, the plus (+) operator can be used in place of &. The difference is that + attempts addition when used with at least one numeric expression, whereas & always concatenates.

Example

This example assigns a concatenated string to variable s$ and a string to s2$, then concatenates the two variables and displays the result in a dialog box.

Sub Main()
  s$ = "This string" & " is concatenated"
  s2$ = " with the '&' operator."
  MsgBox s$ & s2$
End Sub

See Also

+ (operator); Operator Precedence (topic).

More information

Symbols