i want to read strings from multiple lines , \\s+“...
# getting-started
h
i want to read strings from multiple lines , \\s+“.toRegex() would not help as it merely reads one or more whitespaces but not multiple lines. how would u approach ?:
Copy code
val lines = readln().split("\\s+".toRegex()).map { it }.toMutableList()
println(lines.joinToString(" ,   "))
r
If you want to read multiple lines from stdin then
readln()
is a bad choice because as the doc states, it terminates upon LF/CRLF. Therefore, you either have to read the lines in a loop or use something like
Copy code
val scanner = Scanner(System.`in`)
val readText = scanner.nextLine()
👍 1
k
How many lines do you want to read? Or, what is your terminating condition?
h
As much as available, could me anywhere between 2 to 15
k
In that case, it's just:
Copy code
val lines = System.`in`.reader().readLines()