
- VBScript Tutorial
- VBScript - Home
- VBScript - Overview
- VBScript - Syntax
- VBScript - Enabling
- VBScript - Placement
- VBScript - Variables
- VBScript - Constants
- VBScript - Operators
- VBScript - Decisions
- VBScript - Loops
- VBScript - Events
- VBScript - Cookies
- VBScript - Numbers
- VBScript - Strings
- VBScript - Arrays
- VBScript - Date
- VBScript Advanced
- VBScript - Procedures
- VBScript - Dialog Boxes
- VBScript - Object Oriented
- VBScript - Reg Expressions
- VBScript - Error Handling
- VBScript - Misc Statements
- VBScript Useful Resources
- VBScript - Questions and Answers
- VBScript - Quick Guide
- VBScript - Useful Resources
- VBScript - Discussion
Concatenation Operators in VBScript
VBScript supports the following Concatenation operators −
Assume variable A holds 5 and variable B holds 10 then −
Operator | Description | Example |
---|---|---|
+ | Adds two Values as Variable Values are Numeric | A + B will give 15 |
& | Concatenates two Values | A & B will give 510 |
Example
Try the following example to understand the Concatenation operator available in VBScript −
<!DOCTYPE html> <html> <body> <script language = "vbscript" type = "text/vbscript"> Dim a : a = 5 Dim b : b = 10 Dim c c = a+b Document.write ("Concatenated value:1 is " &c) 'Numeric addition Document.write ("<br></br>") 'Inserting a Line Break for readability c = a&b Document.write ("Concatenated value:2 is " &c) 'Concatenate two numbers Document.write ("<br></br>") 'Inserting a Line Break for readability </script> </body> </html>
When you save it as .html and execute it in Internet Explorer, then the above script will produce the following result −
Concatenated value:1 is 15 Concatenated value:2 is 510
Concatenation can also be used for concatenating two strings. Assume variable A="Microsoft" and variable B="VBScript" then −
Operator | Description | Example |
---|---|---|
+ | Concatenates two Values | A + B will give MicrosoftVBScript |
& | Concatenates two Values | A & B will give MicrosoftVBScript |
Example
Try the following example to understand the Concatenation operator available in VBScript −
<!DOCTYPE html> <html> <body> <script language = "vbscript" type = "text/vbscript"> Dim a : a = "Microsoft" Dim b : b = "VBScript" Dim c c = a+b Document.write ("Concatenated value:1 is " &c) 'Numeric addition Document.write ("<br></br>") 'Inserting a Line Break for readability c = a&b Document.write ("Concatenated value:2 is " &c) 'Concatenate two numbers Document.write ("<br></br>") 'Inserting a Line Break for readability </script> </body> </html>
When you save it as .html and execute it in Internet Explorer, then the above script will produce the following result −
Concatenated value:1 is MicrosoftVBScript Concatenated value:2 is MicrosoftVBScript
vbscript_operators.htm
Advertisements