Kotlin Strings
$count++; if($count == 1) { include "../mobilemenu.php"; } if ($count == 2) { include "../sharemediasubfolder.php"; } ?>
Strings in Kotlin represent an array of characters.
Strings are immutable. It means operations on string produces new strings.
We can create string as follows in Kotlin.
val x: String = "Hello World"
Or we can create a multi line string as follows.val x: String = """The
Quick
Brown
Fox"""
String templates:
String templates is a powerful feature in Kotlin when a string can contain expression and it will get evaluated.
Example:
fun main(args: Array<String>) {
val x: String = "Iceberg"
val y: String = "My name is $x"
println(y)
}
Output:
My name is Iceberg
fun main(args: Array<String>) {
var y: String = "Hello"
var x: Char
x = y[1]
print(x)
}
Output:
e
fun main(args: Array<String>) {
var str1: String = "Hello"
for(item in str1)
{
println(item)
}
}
Output:
H
e
l
l
o
fun main(args: Array<String>) {
var s: String = "Hello"
println("Length of string $s is ${s.length}")
println("Init cap of string is ${s.capitalize()}")
println("Lower case is ${s.toLowerCase()}")
println("Upper case is ${s.toUpperCase()}")
}
Output:
Length of string Hello is 5
Init cap of string is Hello
Lower case is hello
Upper case is HELLO