String

Example 1: Simple strings

var name = "John Smith"
var code = 'OX16 OTH'
var poem = "Tam O' Shanter"

Example 2: Combining Strings

One string can be appended to the end of another string using the + sign

var firstName = "John"
var surname = "Smith"
var fullName = firstName + surname

You will note the result placed into fullName is JohnSmith so you may wish to add an intervening space as follows:

var fullName = firstName + " " + surname

When a variable containing a string is added to a variable containing a number, the resulting variable is a string data type, as follows (again we’ve add a space between the two)

var first = "Room"
var second = 101
var result = first + " " + second // result = "Room 101"

Example 3: Numbers in strings

When numbers are surrounded by quote marks, they are considered a string

var x = "12" + "34" // x = "1234"

Example 4: Special characters

Some important special characters can be inserted into a string by using the backslash character ( \ ). These are:

(i) \n – a new line. This is useful if you are using the Debug.trace function to check your script because you can separate information from variables on different lines.

Debug.trace( "The answer are: " + answerA + "\n" + answerB)

(ii) \t – a tab. This is useful if you want to insert a tab in a file opened with the OpenFile function.

var textObj = OpenFile("c:\\myText.txt")
writeString = "John" + "\t" + "Smith" + "\n"
textObj.WriteLine(writeString)

(iii) \\ - a backslash character. If you need to write a pathname, you will need to enter double slashes to indicate sub-folders in the path.

var graphicPath = "c:\\Images\\businessGraphic.png"

Close