带有示例的 Scala String lastIndexOf(String str) 方法
lastIndexOf(String str)方法用于从指定的字符串返回我们在参数中指定的子字符串的最后出现的索引。
Method Definition: int lastIndexOf(String str)
Return Type: It returns the index of the last appearance of the sub-string specified in the argument.
示例 #1:
// Scala program of int lastIndexOf()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying lastIndexOf method
val result = "GeeksforGeeks".lastIndexOf("ek")
// Displays output
println(result)
}
}
输出:
10
示例 #2:
// Scala program of int lastIndexOf()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying lastIndexOf method
val result = "GeeksforGeeks".lastIndexOf("Geek")
// Displays output
println(result)
}
}
输出:
8