当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Scala String lastIndexOf(String str)用法及代码示例


lastIndexOf(String str)方法用于从声明的字符串返回我们在参数中指定的子字符串的最后一次出现的索引。

函数定义: int lastIndexOf(String str)
返回类型: It returns the index of the last appearance of the sub-string specified 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("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


相关用法


注:本文由纯净天空筛选整理自nidhi1352singh大神的英文原创作品 Scala String lastIndexOf(String str) method with example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。