String Concatenation Operator (+)
The string concatenation operator (+
) in OSL joins two strings together with a space automatically inserted between them.
Syntax
Description
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
Mixed Type Concatenation
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?