Open In App

Scala String trim() method with example

Improve
Improve
Like Article
Like
Save
Share
Report

The trim() method is utilized to omit the leading and trailing spaces in the stated string.

Method Definition: String trim()

Return Type: It returns the stated string after removing all the white spaces.

Example: 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)
      
    }


Output:

Nidhi Singh

Example: 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)
      
    }


Output:

Nidhi Singh GfG


Last Updated : 29 Oct, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads