- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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]
- Related Articles
- How to split a string into elements of a string array in C#?
- How do I search through an array using a string, which is split into an array with JavaScript?
- PHP program to split a given comma delimited string into an array of values
- How to split comma and semicolon separated string into a two-dimensional array in JavaScript ?
- How to convert an image into base64 String in Android using Kotlin?
- How to split a string column into multiple columns in R?
- How to split a Java String into tokens with StringTokenizer?
- How to convert an array into JavaScript string?
- How to convert an array of characters into a string in C#?
- Split string into groups - JavaScript
- Split string into equal parts JavaScript
- Split Array into Consecutive Subsequences in C++
- How to convert an ArrayList to String in Kotlin?
- How do I split a multi-line string into multiple lines?
- How to split a string in Python

Advertisements