is there no equivalent
# stdlib
a
is there no equivalent
s
sure there is
"string".split(" ", limit = 2)
a
that’s what I have though :((
s
ok mr 👎
those red lines come with an error message
care to share what that message is
’cause that one-liner I posted is valid Kotlin according to my IntelliJ
a
none of these following functions can be called using the arguments supplied
:?
wtf ??
it works when I add the ‘limit =’
`
Copy code
"asd".split(" ", limit = 2)
works
Copy code
"asd".split(" ", 2)
` doesn’t :S
s
so that wasn’t what you had
cool
.split()
with a string delimiter is a three argument function call — if you skip an argument, you can’t supply the last argument positionally
you have to pass it by keyword
a
gg rip
z
n
You have to realize that the Java
String#split
takes a regex as first parameter. Kotlin (rightfully) requires to pass a Regex instead of a String if the parameter is a regex, and there is the drop-in 2 param equivalent in Kotlin stdlib. Thus, you should use
log.split(" ".toRegex(), 2)
instead of using the 3-param variant that takes a String instead of a regex (which does not exist in the Java stdlib). Of course in your example both would work because your regex
" "
does not contain anything which is not matched literally.