Q:

Write a Scala program to trim any leading or trailing whitespace from a given string

0

Write a Scala program to trim any leading or trailing whitespace from a given string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

object Scala_String {
  def main(args: Array[String]): Unit = {
    {
      val str = " Scala Exercises ";

      // Trim the whitespace from the front and back of the String.
      val new_str = str.trim();
      // Display the strings for comparison.
      println("Original String:-" + str);
      println("New String:-" + new_str);
    }
  }
}

Sample Output:

Original String:- Scala Exercises 
New String:-Scala Exercises

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now