‫In Kotlin, strings are sequences of characters that are used to represent text or textual data.
‫Kotlin provides a rich set of features for working with strings.
‫Let's start with string declaration.
‫You can declare a string variable using either the string class or by using string literals enclosed
‫in double quotes, for example val.
‫Text one is of type string equals to.
‫Hello my friends.
‫The second text.
‫Text two I can omit the string type.
‫I can directly write like this.
‫So this is how we create texts in end strings in Kotlin.
‫Let's move to string concatenation.
‫You can concatenate strings using the plus operator or by using the plus function.
‫For example val text three equals to text one plus text two.
‫So I can concatenate strings by using the plus operator.
‫Let me print text three run and you can see.
‫Hello my friends is concatenated with welcome back text.
‫Here I am joining the two strings.
‫Also I can use the full text.
‫Here I'm concatenating this string with text three that concatenate text one with text two.
‫Run the program and this is what we used in the previous videos.
‫The full text is concatenated with text one plus text two.
‫Kotlin allows you to embed expressions and variables within the strings using string templates.
‫You can use the dollar sign and the curly braces syntax to insert values into a string.
‫For example, val name equals to jack, val age equals to 30 val info equals to.
‫My name is.
‫And here I can use the dollar sign and set the name.
‫So I'm calling the string variable called name here by using the dollar sign and concatenate it inside
‫this string.
‫Print l n the info.
‫Let me run.
‫You can see my name is Jack.
‫This is the variable name.
‫The value is Jack.
‫So it is concatenated directly by using the dollar sign.
‫And I am 30 years old.
‫Age is 30.
‫Age variable is replaced by its value.
‫This is called the string template.
‫Now let's move to the string interpolation.
‫String interpolation allows you to evaluate expressions within string templates.
‫For example, val x equals to five, val y equals to three.
‫I need to evaluate these variables.
‫So for that val result equals to the sum of I'm calling x.
‫Here is the value of x will be displayed and the value of y is.
‫You can use the dollar sign.
‫And this curly braces x plus y.
‫These are in orange color the dollar sign.
‫And this syntax the dollar sign and the curly braces print Len the result.
‫Run the program and you can see the sum of five.
‫I'm getting the value of x and the value of y.
‫This is what we learned about in the string templates here.
‫The string interpolation I'm getting the variable x plus variable y and I'm returning the result of
‫summation equals to eight.
‫Of course you can use other operators like multiplication, division, modulus and so on okay.
‫Kotlin's string class provides various functions and properties for working with strings.
‫Some commonly used ones include.
‫Length is empty.
‫Method is blank.
‫Method two uppercase method, two lowercase method sub string, and more.
‫Text equals to two.
‫Welcome to our course.
‫I need to get the length so the length of this text equals to text dot.
‫And there are a lot of things we can call.
‫I'm using the dot operator that calls the functions inside this object.
‫I'll use the length.
‫Now I need to print this length.
‫I'm using the concatenation and here run the program.
‫The length of text is 21 including the empty spaces.
‫So this is how we get the length of the text.
‫Also I can use uppercase.
‫Subtext is blank is empty or not.
‫So if I need to get a substring, create a substring of the first.
‫For example, eight letters I can create val sub text equals to text dot sub string method and I need
‫to get the start index which is from
‫00123456.
‫So I need the first.
‫I need to make it seven because the last index is not included.
‫And create a new print line method the substring.
‫On the program.
‫And you can get the substring is welcome.
‫So I'm creating a sub text substring from the original string.
‫Also I can compare strings.
‫You can compare strings using the equals equals operator for content equality and equals function.
‫Or use compare two function.
‫For example here we have string str one and str two.
‫I'm using equals function to check if str one equals to str two print ln string.
‫And here I'm calling this string comparison valuable.
‫Run and you can see the string comparison result is equal to false because hello is not equal to hi.
‫Now let me change Str1 and Str2 to be similar.
‫Run the program and you can get true because str one equals to str two.
‫Kotlin supports escape sequences in string literals to represent special characters.
‫For example, val newline text equals to.
‫This is the first line and I'll use backslash and this is for the new line.
‫This is the second line.
‫And if I try to print this variable new line text we can get two lines.
‫Because I used the escape character slash n to represent a new line character.
‫These are some of the fundamental aspects of working with strings in Kotlin.
‫Strings are an essential part of any programming language, and are used extensively for text processing
‫and manipulation in Kotlin as well.