Scala offers many methods for string manipulation, the subSequence
function being one of them. The subSequence
function can be used to get a subsequence or a substring of a piece of text by specifying the starting and ending indices.
CharSequence subSequence(int startIndex, int endIndex)
The subSequence
function takes two parameters:
startIndex
: The index of the string where the subsequence will begin.endIndex
: The index of the string where the subsequence will end.The subSequence
function returns the substring between the starting and ending indices.
The following code shows the implementation of subSequence
function:
object Main extends App{// using subSequence functionval sub_sequence = "This is an Edpresso shot".subSequence(11, 19)// Displays subsquenceprintln(sub_sequence)}
Free Resources