https://kotlinlang.org logo
#getting-started
Title
# getting-started
a

Ananiya

10/30/2020, 10:40 AM
Hello there 👋, i am confused. I take user input then in the user input it might be "bot take rest" and I converted it to list, then I need to verify(put in if else statement) the first 9 words or if the 9 word is "bot take" or another command. How can I do that 9 words ?
n

nfrankel

10/30/2020, 10:44 AM
that’s a bit confusing perhaps you could explain the context?
a

Ananiya

10/30/2020, 10:49 AM
Simply, I just want to take the first 9 words as string from the user input
v

Vampire

10/30/2020, 11:00 AM
But your example only has 3 words
To get the first 9 words as list you can for example do
Copy code
input.splitToSequence(' ', limit = 10).take(9).toList()
Or
Copy code
input.split("""\s+""".toRegex(), limit = 10).take(9)
a

Ananiya

10/30/2020, 11:24 AM
@Vampire sorry, I mean letter but this way (that you tell me in the top) is much straight forward and easy than that I ask (with single letter) thank you very much 😃
v

Vampire

10/30/2020, 11:32 AM
if ("bot take rest".startsWith("bot take ")) { ... }
a

Ananiya

10/30/2020, 11:47 AM
Thanks this also helps
2 Views