Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala strip trailing whitespace

Tags:

The Scala String method (in class StringOps) stripMargin removes leading whitespace from each line of a multi-line String up to and including the pipe (|) character (or other designated delimiter).

Is there an equivalent method to remove trailing whitespace from each line?

I did a quick look through the Scaladocs, but could not find one.

like image 267
Ralph Avatar asked May 18 '11 15:05

Ralph


People also ask

How do you cut a space in Scala?

What is trim() in Scala? The trim() method is used to remove all the leading and trailing spaces that are present in the string. For example, if the string looks like, " Hello World " then there is a lot of empty space before the term “Hello” and after the term “World”. The method trim() is used to remove these spaces.

How do you remove leading and trailing whitespace from a string?

To remove leading and trailing spaces in Java, use the trim() method. This method returns a copy of this string with leading and trailing white space removed, or this string if it has no leading or trailing white space.

Which function removes Allleading and trailing Whitespaces Instring?

strip(): returns a new string after removing any leading and trailing whitespaces including tabs ( \t ). rstrip(): returns a new string with trailing whitespace removed. It's easier to remember as removing white spaces from “right” side of the string.

What is stripMargin in Scala?

stripMargin ( '#' ) All of these approaches yield the same result, a multiline string with each line of the string left justified: Four score and seven years ago. This results in a true multiline string, with a hidden \n character after the word “and” in the first line.


1 Answers

Java String method trim removes whitespace from beginning and end:

scala> println("<"+"  abc  ".trim+">") <abc> 
like image 128
Daniel C. Sobral Avatar answered Sep 28 '22 08:09

Daniel C. Sobral