String Concatenation Operator (+)
The string concatenation operator (+) in OSL joins two strings together with a space automatically inserted between them.
Syntax
string1 + string2Description
Unlike many other programming languages where + simply joins strings without adding spaces, the OSL + operator automatically inserts a space between the concatenated strings. This makes it particularly useful for building readable sentences and text.
If either operand is a string, the other operand will be converted to a string and the operation will use string concatenation rules.
Examples
Basic String Concatenation
result = "hello" + "world"
log result // Outputs: "hello world"
// Notice the space is automatically added between "hello" and "world"Mixed Type Concatenation
// Concatenating strings with numbers
message = "The answer is" + 42
log message // Outputs: "The answer is 42"
// Concatenating multiple items
fullName = "John" + "Doe" + "Smith"
log fullName // Outputs: "John Doe Smith"Building Sentences
Comparison with Other String Operators
+ vs. ++ Operator
OSL provides two different operators for string operations:
+ vs. .append() Method
The .append() method attaches a string to the end without adding a space:
Notes
The automatic space insertion is a feature specific to OSL and differs from many other programming languages.
When working with formats where spaces matter (like URLs or file paths), use the
++operator instead.The string concatenation behavior applies whenever either operand is a string.
Last updated
Was this helpful?