开发者

Syntactic sugar string concatenation when updating variable

In most programming languages I have used you can do something like (where s is a string).

s = "Hello"
s += " Wo开发者_JS百科rld"

I try to do something similar in VBA and it does not work. I have tried

s = "Hello"
s += " World" 
s &= " World" 

In the end I have done

s = "Hello"
s =  s & " World" 

Can I do this without the s &


Microsoft Access doesn't use VB.NET and the &= concatenation operator is VB.NET specific.

Even in Access 2010 VBA is still VB6.5 (old school P-Code|Native/COM VB) and hasn't been upgraded to use VB.NET.


VBA has two concatenation operators - the & and the +.

However, it doesn't have the shortcut of =+ or =& - you have to write the full syntax:

s = s & " World"

Or

s = s + " World"

Though + comes with a warning (since it is also used as the addition operator):

Although you can also use the + operator to concatenate two character strings, you should use the & operator for concatenation to eliminate ambiguity and provide self-documenting code.


Yes, but it's not better than just using the ampersand

s = "Hello"
s = Join(Array(s, "World"))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜