+ 2
How to split string into substring in kotlin??
4 Réponses
+ 9
Ritesh Singh
var a:String=readLine()!!.toString()
var arr=a.split(",")
print(arr[1])
+ 8
Use substring() method
var a:String="hello"
print(a.substring(1,3))
//output: el
+ 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.
+ 1
I just want to split a string by "," by given symbol to array of string.