A string is a basic data type in a programming language. In Kotlin, the String class represents character strings. Kotlin string literals are implemented as instances of this class. Kotlin uses double quotes to create string literals.
Kotlin has a rich API for working with strings. It contains plenty of methods for various string operations. Kotlin/Java strings are immutable, which means that all modification operations create new string instead of modifying a string in-place.
Kotlin strings tutorial shows how to work with strings in Kotlin.
Kotlin String and String Templates
In this tutorial, you will learn about Kotlin strings, string templates, and few commonly used string properties and functions with the help of examples.
Kotlin String
Strings are a sequence of characters. For example, "Hello there!" is a string literal.
In Kotlin, all strings are objects of String class. Meaning, string literals such as "Hello there!" are implemented as instances of this class.
String Literals
A literal is the source code representation of a fixed value. For example, "Hey there!" is a string literal that appears directly in a program without requiring computation (like variables).
There are two types of string literals in Kotlin:
1. Escaped string
A escaped string may have escaped characters in them. For example,
Here, \n is an escape character which inserts a newline in the text where it appears.
2. Raw String
A raw string can contain newlines (not new line escape character) and arbitrary text. A raw string is delimited by a triple quote
Kotlin String
An array of characters is called a string. Kotlin strings are mostly similar to Java strings but has some new added functionalities. Kotlin strings are also immutable in nature means we can not change elements and length of the String.
The String class in Kotlin is defined as:
To declare a string in Kotlin, we need to use double quotes(” “), single quotes are not allowed to define Strings.
Creating an empty String:
To create an empty string in Kotlin, we need to create an instance of String class.
String elements and templates –
String Element –
The character, digit or any other symbol present in string is called as element of a String. We can easily access the element of the string using string[index]. Elements store in a string from index 0 to (string.length – 1).
There are three ways in which you can access string elements in Kotlin –
Using index: Returns the character at specified index.
Using get function: Returns the character at specified index passed as argument to get function.
Iterating over the String: Using loops to access the characters in the String.
Follow my Facebook Page : / 105940115222549
Follow me on Instagram : / cviulw2somi
Follow me on tumblr : / programming-guru
Follow me on reddit : https://www.reddit.com/u/Programming_...
Strings in Kotlin | Raw String and Escaped String in kotlin | Android Kotlin Strings
Strings in Kotlin | Raw String and Escaped String in kotlin | Android Kotlin Strings
Strings in Kotlin | Raw String and Escaped String in kotlin | Android Kotlin Strings
Strings in Kotlin | Raw String and Escaped String in kotlin | Android Kotlin Strings
Programming Guru,Guru Programming,programming,gurru,programminggurru,Strings in Kotlin,Raw String and Escaped String in kotlin,Android Kotlin Strings,program,kotlin,kotlin programming,kotlin programming language,kotlin tutorial,learn kotlin,kotlin android,kotlin programming tutorial,kotlin language,kotlin for android,string in kotlin,programming tutorial,learn kotlin programming language,kotlin android tutorial,android kotlin,kotlin for android developers