“+”和“&”的區別

注意:& 兩邊都要用空格,否則會報錯!

"+":
       1. 如果兩個表達式都是Numeric ,則相加;
       2. 如果兩個表達式都是String ,則連接;
       3.如果一個表達式是Numeric ,另一個是String(僅行數字的String),把String 轉換成Numeric ,再相加。

       4.如果一個表達式是Numeric,另一個是String(含非數字的String),則會報錯,不允許這樣。

 "&": 把兩個表達式都轉換成string,然後連接。
舉例:

        1.MsgBox 1+3 結果是:4

        2.MsgBox 1+"3" 結果是:4

        3.MsgBox 1+"hello" 結果要報錯

        4.MsgBox "hello"+"hi" 結果是:hellohi

        5.MsgBox 1 & 3 結果是:13

        6.MsgBox 1 & "3" 結果是:13

        7.MsgBox 1 & "hello" 結果是:1hello

        8.Msgbox "hello" & "hi" 結果是:hellohi

由此可見,如果是字符串相連,最好用&

 

發佈了20 篇原創文章 · 獲贊 10 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章