📌  相关文章
📜  带有示例的 Scala String compareToIgnoreCase() 方法

📅  最后修改于: 2022-05-13 01:54:36.170000             🧑  作者: Mango

带有示例的 Scala String compareToIgnoreCase() 方法

compareToIgnoreCase()方法用于比较两个字符串,如compareTo方法,但在比较时忽略大小写(大写或小写)差异。

示例:1#

// Scala program of compareToIgnoreCase()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
        // Creating a String
        val m1 = "Nidhi"
          
        // Applying compareToIgnoreCase() method
        val result = m1.compareToIgnoreCase("Nidhi")
          
        // Displays output
        println(result)
      
    }
} 
输出:
0

示例 #2:

// Scala program of compareToIgnoreCase()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
        // Creating a String
        val m1 = "Nidhi"
          
        // Applying compareToIgnoreCase() method
        val result = m1.compareToIgnoreCase("NiDhi")
          
        // Displays output
        println(result)
      
    }
} 
输出:
0

在这里,即使存在大小写差异,两个字符串也被认为是相同的。
示例#3:

// Scala program of compareToIgnoreCase()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
        // Creating a String
        val m1 = "Nidhi"
      
        // Applying compareToIgnoreCase() method
        val result = m1.compareToIgnoreCase("NiDh")
      
        // Displays output
        println(result)
      
    }
} 
输出:
1