Scala 字符串 lastIndexOf(String str)方法及示例

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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程