Scala 字符串regionMatches() 方法及示例

Scala 字符串regionMatches() 方法及示例

regionMatches() 方法用于检查两个字符串区域是否相等。然而,如果在参数列表中ignoreCase为true,那么将忽略大小写差异。

方法定义。Boolean regionMatches(boolean ignoreCase, int toffset, String other, int offset, int len)
返回类型。如果两个字符串区域匹配,则返回真,否则返回假。

例子 #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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程