indexOf(int ch,int fromIndex)方法與indexOf()方法相同,但是在這裏此方法開始從我們指定的索引中查找字符。
函數定義: int indexOf(int ch, int fromIndex)
返回類型: It returns the index of the character 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 = "Nidhi".indexOf('i', 2)
// Displays output
println(result)
}
}
輸出:
4
因此,這裏的“ i”第一次出現是在第二個索引為4之後。因此,將4作為輸出返回。
範例2:
// Scala program of int indexOf()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying indexOf method
val result = "NidhiSingh".indexOf('h', 4)
// Displays output
println(result)
}
}
輸出:
9
在這裏,“ h”在第四個索引之後的第一個出現是9。因此,它返回了。
相關用法
- Scala String lastIndexOf(String str, int fromIndex)用法及代碼示例
- Scala String indexOf(String str, int fromIndex)用法及代碼示例
- Scala String regionMatches(int toffset, String other, int offset, int len)用法及代碼示例
- Scala String startsWith(String prefix, int toffset)用法及代碼示例
- Scala String split(String regex, int limit)用法及代碼示例
- Scala String startsWith(String prefix)用法及代碼示例
- Scala String indexOf(String str)用法及代碼示例
- Scala String lastIndexOf(String str)用法及代碼示例
- Scala String matches()用法及代碼示例
- Scala String toLowerCase()用法及代碼示例
- Scala String regionMatches()用法及代碼示例
- Scala String subSequence()用法及代碼示例
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Scala String indexOf(int ch, int fromIndex) method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。