VBScript 中的連線運算子



VBScript 支援以下連線運算子 -

假設變數 A 儲存 5,變數 B 儲存 10,則 -

運算子 說明 示例
+ 如果變數值為數字,則將兩個值相加 A + B 將輸出 15
& 將兩個值連線起來 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.htm
廣告