splitToSequence

Common
JVM
Native
1.6
fun splitToSequence (
input : CharSequence ,
limit : Int = 0
) : Sequence < String >

(Common source) (JVM source) (Native source)
JS
1.6
fun splitToSequence (
input : CharSequence ,
limit : Int = 0
) : <ERROR CLASS> < String >

(source)

Splits the input CharSequence to a sequence of strings around matches of this regular expression.



fun main(args: Array<String>) {
//sampleStart
val colors = "green, red , brown&blue, orange, pink&green"
val regex = "[,\\s]+".toRegex()

val mixedColor = regex.splitToSequence(colors)
    .onEach { println(it) }
    .firstOrNull { it.contains('&') }

println(mixedColor) // brown&blue
//sampleEnd
}

Parameters

limit - Non-negative value specifying the maximum number of substrings the string can be split to. Zero by default means no limit is set.