String Templates

Reading Time: < 1 minute

String templates are used to insert a variable’s value into a string. String literals may contain template expressions, i.e. pieces of code that are evaluated and whose results are concatenated into the string.

A template expression starts with a dollar sign ($) and consists of either a simple name.


Value is 5

Anything in the curly brackets starting with a $ sign will be evaluated and the result will be put in the string.


Sum is 11
Note that we have used expression ${name.length} to get the character length of variable name.

Kotlin String template with raw string

We have already seen how to use string template with escaped string. Now, we will see how to use string templates with raw string.

Like escaped string, string template in raw string  starts with $ sign.


$200

 

Questions

I hope the description was understandable and clear. But if you have still questions, then leave me comments below! 😉

Have a nice a day! 🙂

 


 

Follow and like us:
Click to rate this post!
[Total: 0 Average: 0]

Leave a comment

stay informed!

Subscribe to receive exclusive content and notifications