split

fun CharSequence.split(regex: Pattern, limit: Int = 0): List<String>(source)

Splits this char sequence around matches of the given regular expression.

This function has two notable differences from the method Pattern.split:

  • the function returns the result as a List<String> rather than an Array<String>;

  • when the limit is not specified or specified as 0, this function doesn't drop trailing empty strings from the result.

Since Kotlin

1.0

Parameters

limit

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