Kotlin Split String example

This Kotlin tutorial shows you ways to split string with Kotlin extension functions.

I. Technology

– Java 1.8
– Kotlin 1.1.2

II. Overview

1. split() with Regex

This overload of split() method requires a value of Regex type, not String:

Kotlin not only uses the same regular expression syntax and APIs as Java, but also has extension function toRegex() to convert a string into a regular expression.
So, our code could be:

2. split() with plain-text characters/strings

Instead of using Regex, you can specify character/string arguments:

III. Practice

1. split() with Regex

Result:

2. split() with plain-text characters/strings

Result:

By JavaSampleApproach | August 29, 2017.


Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*