Concatenating

You can use "+" for concatenation although it is not recommended as this is a WordBasic operator. You should use "&".
When using the string concatenation character "&" be sure to insert a space before and after this operator.


String Concatenation (&)

This operator can be used to join two or more strings together.
This operator can also automatically convert between types as it combines a resultant string.
It can be used to combine several different variable types into a string without any explicit conversion.

Dim sMyLongString As String 
Dim sShortString As String
sShortString = "Monday"
sMyLongString = sShortString & " " & "some more text"
Msgbox sMyLongString ' = "Monday some more text"

String Concatenation (+)

This can also be used as a string addition operator to join two or more strings together.
If you try to use this operator with multiple variables types you will receive a "Type Mismatch" error.

Dim MyNumber As Variant 
MyNumber = "2"
MyNumber = MyNumber + MyNumber + MyNumber
Msgbox MyNumber ' "222"

JOIN Function

JOIN - Returns a text string containing all the elements in an array (String).


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext