W3cubDocs

/Kotlin

split

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun CharSequence.split(
    vararg delimiters: String, 
    ignoreCase: Boolean = false, 
    limit: Int = 0
): List<String>

Splits this char sequence to a list of strings around occurrences of the specified delimiters.

Parameters

delimiters - One or more strings to be used as delimiters.

ignoreCase - true to ignore character case when matching a delimiter. By default false.

limit -

The maximum number of substrings to return. Zero by default means no limit is set.

To avoid ambiguous results when strings in delimiters have characters in common, this method proceeds from the beginning to the end of this string, and matches at each position the first element in delimiters that is equal to a delimiter in this instance at that position.

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun CharSequence.split(
    vararg delimiters: Char, 
    ignoreCase: Boolean = false, 
    limit: Int = 0
): List<String>

Splits this char sequence to a list of strings around occurrences of the specified delimiters.

Parameters

delimiters - One or more characters to be used as delimiters.

ignoreCase - true to ignore character case when matching a delimiter. By default false.

limit - The maximum number of substrings to return.

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun CharSequence.split(
    regex: Regex, 
    limit: Int = 0
): List<String>

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

Parameters

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

Platform and version requirements: JVM (1.0)
fun CharSequence.split(
    regex: Pattern, 
    limit: Int = 0
): List<String>

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.

Parameters

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

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/split.html