Home > Articles

  • Print
  • + Share This

Concatenating Strings

You can combine strings together and assign them to a variable by using the string concatenation operator, the ampersand, &, as follows:

s = "This is " & "really cool"

Also, in VBScript you can use the plus sign (+) to concatenate strings. The following code is quite valid:

s = "This is " + "really cool"

However, be advised that if you do use the plus sign, you do run the risk of error. The following code will cause an error in the script:

s = "This is " + 5

In the previous example, the raw data is made up of two primitive types, a string ("This is ") and an integer (5). The plus sign does not know how to reconcile the two different types to get them to work together. However, the ampersand has enough built-in smarts to reconcile the two different data types. Thus, this code works perfectly well:

s = "This is " & 5
  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.