Tutorial by Examples

Elements of String are characters that can be accessed by the indexing operation string[index]. val str = "Hello, World!" println(str[1]) // Prints e String elements can be iterated with a for-loop. for (c in str) { println(c) }
Kotlin has two types of string literals: Escaped string Raw string Escaped string handles special characters by escaping them. Escaping is done with a backslash. The following escape sequences are supported: \t, \b, \n, \r, \', \", \\ and \$. To encode any other character, use the Unicod...
Both escaped strings and raw strings can contain template expressions. Template expression is a piece of code which is evaluated and its result is concatenated into string. It starts with a dollar sign $ and consists of either a variable name: val i = 10 val s = "i = $i" // evaluates to ...
In Kotlin strings are compared with == operator which chect for their structural equality. val str1 = "Hello, World!" val str2 = "Hello," + " World!" println(str1 == str2) // Prints true Referential equality is checked with === operator. val str1 = ""&q...

Page 1 of 1