CAS Scripting introduces a new root level "cseval" method simplifying writing complex string concatenation expressions. The method will take the "ToString" value of any evaluated object.
Until now, it was required to use the ToString method of each compatible object before adding or concatenating text to a CharString.
name ← CharString.New 'Application'
date ← DateStamp.New 0
list ← StringList.New 'one' 'two' 'three'
out ← CharString.New''
out.Add 'The User '
out.Add name
out.Add ' was added on '
out.Add date.ToString ''
out.Add ' with three items; '
out.Add list.ToString ','
out.Show''
This now be accomplished with cseval. Any object placed between braces will be interpolated for the final result of ToString ''.
name ← CharString.New 'Application'
date ← DateStamp.New 0
list ← StringList.New 'one' 'two' 'three'
num ← Numeric.New 123
out ← CharString.New cseval 'The User {name}{num} was added on {date} with three items; {list}.'
out.Show''
Anytime you want to use curly brackets without interpolation, the opening bracket must be escaped with a backslash.
name ← CharString.New 'Steve'
cs ← cseval 'My name is \{name}'
The result will be
My name is \{name}
To include a backslash next to an interpolated string, use an escaped backslash with a double backslash. This is useful when working with file paths.
name ← CharString.New 'Steve'
cs ← cseval 'My name is \\{name}'
My name is \Steve