Scala: Replace newline, tab and return sequences from string

后端 未结 1 1686
既然无缘
既然无缘 2021-02-12 12:29

I have a string of HTML that I\'m copy pasting into a String object that looks something like the following:

val s = \"\"\"
   

This is a tes

1条回答
  •  没有蜡笔的小新
    2021-02-12 13:09

    You could just

    s.filter(_ >= ' ')
    

    to throw away all control characters.

    If you want to omit extra whitespace at the start/end of lines also, you can instead

    s.split('\n').map(_.trim.filter(_ >= ' ')).mkString
    

    0 讨论(0)
提交回复
热议问题