Strings are used for storing text. A string contains a collection of characters surrounded by double quotes.
var greeting = "Hello"
A String in Kotlin is an object, which means it contains properties and functions that can perform certain operations.
For example, to find the length of a string, use the length property:
val txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
println("The length of the txt string is: " + txt.length)
Kotlin features a fantastic way to insert variables directly inside a string without needing to use the + operator. You simply use the $ symbol followed by the variable name. This is known as String Templates.
fun main() {
val firstName = "John"
val lastName = "Doe"
println("My name is $firstName $lastName")
}