[VB6] 串连运算子 & and +
在VB6中,有两种串连运算子
分别介绍如下:
1. + Operater
主要是用来将数字相加, 但也可用于两个字串间的串连
2. & Operator
主要用来将字串的串连, 且它会一律将运算元转换成String后再做串连
因此也是一般建议用来作为字串串连的运算子, 比较不会因型别出错而造成串联字串时发生错误
MSDN举了一个例子如下:
Dim a As String = "abc" Dim d As String = "def" Dim z As String = a & d Dim w As String = a + d ' The preceding statements set both z and w to "abcdef".
这边可以看到当运算元皆为字串时, 两种运算子的作用是相同的
References:
1. https://msdn.microsoft.com/zh-tw/library/te2585xw.aspx