Operations on the string data type
As we code, there are many occasions where we need to manipulate the representation of a string, be it writing a customized result to output or manipulating the string to use it for further evaluation.
String interpolation
String interpolation is the way to represent a string, along with a mix of different types of variables that get evaluated to their value and converted to the string data type during runtime.
String interpolation of primitive data types
String interpolation is achieved by the following syntax:
println('SAMPLE TEXT $primitive-data-type')
The preceding syntax shows how to perform string interpolation on primitive data types using the $
symbol as a prefix to the variable name. Consider the following code:
a := 'coding' b := 'fun' println('$a is $b')
Here is the output:
coding is fun
When accessing struct fields, it is recommended to wrap them with {
and }
double...