Splitting strings

We need to split the line into a list of strings to get the values of columns into an index based list. Hence, we use an extension function named split, which is injected into CharSequence. It is part of the standard library.

The split function splits the specified string, using the specified deliminator, and returns a list of strings:

    fun CharSequence.split(vararg delimiters: String, ignoreCase:      Boolean, limit: Int) : List<String> 

The following parameters can be used:

  • delimiters: One or more deliminator to split the string.
  • ignoreCase: True to ignore character case when matching a delimiter. By default it's false.
  • limit: Maximum number of substrings to return. By default, it's zero, meaning that no limit is set.

Get Kotlin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.