VBScript Concatenation operator



VBScript Concatenation operator is used to concatenate numeric and string values. In VBScript Concatenation process is achieved using two operators ‘&’ and ‘+’ operator.

VBScript concatenate operator

Consider below table –

Operand 1 Operand 2 Operator Output
Numeric Value Numeric Value + It will perform numeric addition of two values
Numeric Value Numeric Value & It will perform concatenation of two values
Text Value Text Value + It will perform concatenation of two values
Numeric Value Numeric Value & It will perform concatenation of two values

Example 1 : Addition of Numeric Values

Assume variable A holds 15 and variable B holds 20 then –

<!DOCTYPE html>
<html>
<body>
<script language="vbscript" type="text/vbscript">
  Dim a : a = 15
  Dim b : b = 20
  Dim result

  result = a + b 
  Document.write ("Result of Operation " & result) 'Numeric addition
  
  result = a & b 
  Document.write ("Result of Operation " & result) 'Concatenate two numbers 

  </script>
</body>
</html>

After running program in IE following output will be produced –

Result of Operation 35
Result of Operation 1520

Example 2 : Addition of String Values

Assume variable A holds 15 and variable B holds 20 then –

<!DOCTYPE html>
<html>
<body>
<script language="vbscript" type="text/vbscript">
  Dim a : a = "google."
  Dim b : b = "com"
  Dim result

  result = a + b 
  Document.write ("Result of Operation " & result) 'Concatenate two strings
  
  result = a & b 
  Document.write ("Result of Operation " & result) 'Concatenate two numbers 

  </script>
</body>
</html>

After running program in IE following output will be produced –

Result of Operation google.com
Result of Operation google.com