Removing multiple character types from a string
There would be no significant difference, since there is only 3 characters to remove and no so big string to filter, but you may consider to use Set for this purpose. E.g.
val toRemove = "ilr".toSet
val words = sentence.filterNot(toRemove)
I'd just use Java's good old replaceAll
(it takes a regexp):
"Twinkle twinkle little star, oh I wander what you are" replaceAll ("[ilr]", "")
// res0: String = Twnke twnke tte sta, oh I wande what you ae
In contrast to working with char
s (as in filtering a Seq[Char]
), using regular expressions should be Unicode-safe even if you're working with code points outside the basic multilingual plane. "There Ain't No Such Thing As Plain Text."