The subSequence() Function is used to return a new string starting from the start and end index.
fun main() { var x = "Hello Girl" var y = x.subSequence(6, 10) println(y) }
In the above code, we have declared a String 'Hello Girl'.
Now, we will extract the substring 'Girl' from the String 'Hello Girl'.
So, we have used the 'subSequence()' to extract the substring 'Girl'.
So, the substring 'Girl' starts from index/position '6' to '9'. But to extract 'Girl',we have used '6' to '10'(And not '9').
Looks little weird?
Well! This is how it is.
Just remember, the end index should be the (End index value + 1). i.e. The end index for 'Girl' is '9' but we have used '10'.