📜  带有示例的 Scala String trim() 方法

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

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

trim()方法用于省略指定字符串中的前导和尾随空格。

示例:1#

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

示例:2#

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