 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to split a String into an array in Kotlin?
In this article, we will take a couple of examples to demonstrate how we can split a given String in Kotlin using some given delimiters.
Example – Split a String using given delimiters
In this example, we will create a String and we will store some value in it and we will try to split the same using some delimiters.
fun main(args: Array<String>) {    var str = "Tut@or@ia@lsPo@int.@com"    var delimiter = "@"    // It will split the given String using '@'    val parts = str.split(delimiter)    print(parts) }  Output
It will generate the following output −
[Tut, or, ia, lsPo, int., com]
Example – Split a String using multiple delimiters
fun main(args: Array<String>) {    var str = "Tu#t@or@ia#@lsP#o@int.@com"    // passing multiple delimiters    val parts = str.split("#","@")    print(parts) }  Output
On execution, it will produce the following output −
[Tu, t, or, ia, , lsP, o, int., com]
Advertisements
 