String.length is a property in Kotlin that is used to find the length of a string.
String.length
The function returns an integer value, i.e., the number of characters in String.
Let’s look at an example. In the code below, we create two strings, str1 and str2. We then use the length function in line 5 and line 11 to display the lengths of the strings.
fun main(args: Array<String>) {// Example 1val str1 = "Educative"print("The length of " + str1 + " is ")print(str1.length)print("\n")// Example 2val str2 = "Edpresso"print("The length of " + str2 + " is ")print(str2.length)print("\n")}