VBScript 中的连接运算符

VBScript 支持以下连接运算符 −

假设变量 A 为 5,变量 B 为 10 −

运算符 描述 示例
+ 添加两个值,因为变量值为数字 A + B 将给出 15
& Concatenates two Values A & B 将给出 510

示例

尝试以下示例来了解 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>

当您将其另存为 .html 并在 Internet Explorer 中执行时,上述脚本将产生以下结果 −

Concatenated value:1 is 15

Concatenated value:2 is 510

连接也可用于连接两个字符串。 假设变量 A="Microsoft",变量 B="VBScript",则 −

运算符 描述 示例
+ 连接两个值 A + B 将给出 MicrosoftVBScript
& 连接两个值 A & B 将给出 MicrosoftVBScript

示例

尝试以下示例来了解 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>

当您将其另存为 .html 并在 Internet Explorer 中执行时,上述脚本将产生以下结果 −

Concatenated value:1 is MicrosoftVBScript

Concatenated value:2 is MicrosoftVBScript

vbscript_operators.html