Scala String indexOf(String str, int fromIndex) 方法与示例
indexOf(String str, int fromIndex)方法用于返回从我们在所述字符串中指定的索引中首先出现的子字符串的索引。
Method Definition: int indexOf(String str, int fromIndex)
Return Type: It returns the index of the sub-string from the index specified in the argument.
示例 #1:
// Scala program of int indexOf()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying indexOf method
val result = "Nidhisinghis".indexOf("his", 4)
// Displays output
println(result)
}
}
输出:
9
示例 #2:
// Scala program of int indexOf()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying indexOf method
val result = "Nidhisinghis".indexOf("is", 5)
// Displays output
println(result)
}
}
输出:
10