There are multiple ways to declare and use a string in kotlin and many tweaks are there to change the requirement and produce output like getting the length of the character or checking whether the two strings are similar or not or pointing out a character. String in Kotlin is declared in various and several ways to attain and achieve a different output as per requirement. Now there is one more thing that you can do in a string which is getting the letter in the string by pointing on the character or randomly checking which character exists at that pointed place as follows. In the above program by using the length method we can determine how many characters are there in the string but if we use $ only before the str so it will result in printing the output without the length of the string present so we need to use the dollar sign on both str and length, to do that we need to put both in the curly braces like above to get the proper outputħ. In the following example two words or string are combined using + operator which merges the string, example: fun main(args: Array) ") There are different methods to declare String, some of them are listed below: Val newString = "Example" Declaring String in Kotlin Using Various Methods
0 Comments
Leave a Reply. |