Scala String startsWith(String prefix, int toffset) 方法与示例
startsWith(String prefix, int toffset)方法用于检查所述字符串是否以我们在指定索引处指定的前缀开头。
Method Definition: Boolean startsWith(String prefix, int toffset)
Return Type: It returns true if the string starts with the specified prefix at the specified index else it returns false.
示例:1#
// Scala program of startsWith()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying startsWith method
val result = "GeeksforGeeks".startsWith("eks", 2)
// Displays output
println(result)
}
}
输出:
true
示例:2#
// Scala program of startsWith()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying startsWith method
val result = "GeeksforGeeks".startsWith("Eks", 2)
// Displays output
println(result)
}
}
输出:
false