带有示例的 Scala String lastIndexOf(String str, int fromIndex) 方法
lastIndexOf(String str, int fromIndex)方法用于返回我们在参数中指定的子字符串的最后一次出现的索引,该索引从指定的字符串从右到左指定的索引。
Method Definition: int lastIndexOf(String str, int fromIndex)
Return Type: It returns the index of the last appearance of the sub-string specified in the argument from the specified index.
示例 #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", 12)
// 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", 4)
// Displays output
println(result)
}
}
输出:
0