Insert Variables Into Strings

If you want a deeper guide to Scala, when I was learning I used Programming Scala and Scala for Data Science.

The proper term from this is string interpolation.

Create A Value

// Create some values
val number_of_soldiers: Short = 542
val casualties: Short = 32

Add The Value To A String

print(f"Before the battle we had $number_of_soldiers soldiers. However, now we have ${number_of_soldiers - casualties}.")
Before the battle we had 542 soldiers. However, now we have 510.