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
Ronny Bräunlich
11/07/2023, 1:41 PM
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
Klitos Kyriacou
11/07/2023, 2:37 PM
How many lines do you want to read? Or, what is your terminating condition?
h
Hassaan
11/07/2023, 2:38 PM
As much as available, could me anywhere between 2 to 15