Scala 字符串 lastIndexOf(String str)方法及示例
lastIndexOf(String str) 方法是用来返回我们在参数中指定的子字符串在所述字符串中最后出现的索引。
方法定义:int lastIndexOf(String str)
返回类型。它返回参数中指定的子串最后出现的索引。
例子 #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
极客教程