kotlin get last line of string

To get the last line of a string in Kotlin, you can use the following steps:

  1. Use the lines() function to split the string into a list of lines.
  2. Access the last element of the list using the last() function to retrieve the last line of the string.

Here's an example of how you can achieve this:

val text = "This is the first line.\nThis is the second line.\nThis is the last line."
val lastLine = text.lines().last()
println(lastLine) // Output: "This is the last line."