Scala 字符串 lastIndexOf()方法及示例
lastIndexOf() 方法是用来返回我们在参数中指定的字符在所述字符串中最后出现的索引。
方法定义:int lastIndexOf(int ch)
返回类型。它返回参数中最后出现的字符的索引。
例子 #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('G')
// Displays output
println(result)
}
}
输出。
8
例子#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('e')
// Displays output
println(result)
}
}
输出。
10
极客教程