asad.awadia
05/15/2020, 3:46 PMShawn
05/15/2020, 3:57 PMShawn
05/15/2020, 3:57 PMShawn
05/15/2020, 3:58 PM"string".split(" ", limit = 2)
asad.awadia
05/15/2020, 3:58 PMShawn
05/15/2020, 3:59 PMShawn
05/15/2020, 3:59 PMShawn
05/15/2020, 3:59 PMShawn
05/15/2020, 4:00 PMasad.awadia
05/15/2020, 4:00 PMnone of these following functions can be called using the arguments supplied
:?asad.awadia
05/15/2020, 4:01 PMasad.awadia
05/15/2020, 4:01 PMasad.awadia
05/15/2020, 4:01 PM"asd".split(" ", limit = 2)
works
"asd".split(" ", 2)
` doesn’t :SShawn
05/15/2020, 4:01 PMShawn
05/15/2020, 4:01 PMShawn
05/15/2020, 4:03 PM.split()
with a string delimiter is a three argument function call — if you skip an argument, you can’t supply the last argument positionallyShawn
05/15/2020, 4:03 PMasad.awadia
05/15/2020, 4:03 PMZach Klippenstein (he/him) [MOD]
05/15/2020, 4:04 PMnkiesel
05/15/2020, 7:17 PMString#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.