带有示例的 Scala String regionMatches() 方法
regionMatches()方法用于检查两个字符串区域是否相等。但是,如果在参数列表中将ignoreCase声明为 true,则忽略大小写差异。
Method Definition: Boolean regionMatches(boolean ignoreCase, int toffset, String other, int offset, int len)
Return Type: It returns true if two string region matches else it returns false.
示例 #1:
// Scala program of regionMatches()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying regionMatches method
val result = "Preeti".regionMatches(false, 0, "Preeti", 0, 4)
// Displays output
println(result)
}
}
输出:
true
示例 #2:
// Scala program of regionMatches()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying regionMatches method
val result = "Preeti".regionMatches(true, 0, "pReeti", 0, 4)
// Displays output
println(result)
}
}
输出:
true