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

Gordon Child

08/06/2021, 8:08 PM
I'm having trouble with the kotlin syntax for methods that appear to have a vararg as the first parameter. I'm trying to call
line.split(": ", 2)
(line is a String). I've tried
line.split(": ", false, 2)
and
line.split(delimiters = ": ", limit = 2)
It's telling me...
After a bit more trial and error, this appears to be the correct syntax `
Copy code
val parts = line.split(": ", ignoreCase = false, limit = 2)
or
Copy code
val parts = line.split(": ", limit = 2)
It would be nice if kotlin supported some sort of syntax like this...
Copy code
val [propertyName, propertyValue] = line.split(": ", limit = 2)
e

ephemient

08/06/2021, 8:28 PM
Copy code
val (propertyName, propertyValue) = line.split(": ", limit = 2)
does work thanks to standard
operator fun component1()
etc. extensions. will throw if there's only 1 part though
g

Gordon Child

08/06/2021, 8:32 PM
ahh, that's interesting.. component1. Thanks @ephemient! I'll have to have a try at it.