带有示例的 Scala String lastIndexOf() 方法
lastIndexOf()方法用于从指定的字符串返回我们在参数中指定的字符的最后一次出现的索引。
Method Definition: int lastIndexOf(int ch)
Return Type: It returns the index of the last appearance of the character 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('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