+ 2

How to split string into substring in kotlin??

4th Jun 2018, 1:05 PM
Ritesh Singh
Ritesh Singh - avatar
4 Respostas
+ 9
Ritesh Singh var a:String=readLine()!!.toString() var arr=a.split(",") print(arr[1])
5th Jun 2018, 10:47 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 8
Use substring() method var a:String="hello" print(a.substring(1,3)) //output: el
4th Jun 2018, 1:29 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 3
It can be simplified down to: val arr = readLine()!!.split(",") arr will automatically get typed to Array<String> with arr.size elements. You can make it val as the Array class won't be changing even if you overwrite the contained elements.
17th Jun 2018, 8:29 PM
John Wells
John Wells - avatar
+ 1
I just want to split a string by "," by given symbol to array of string.
4th Jun 2018, 1:43 PM
Ritesh Singh
Ritesh Singh - avatar