1

I have

val content = "bala.ba* muthu.t@ jiang.xin="

How to filter of those junk char(*, @ & = ) in Scala?

For now I am using java substring, which may not the best for scala.

I also tried

filter (_ != "*" ) filter (_ != "@") filter (_ != "=")

Don't feel thats the right way

I would like to go with best functional way

Thanks in advance guys...

serejja
  • 22,901
  • 6
  • 64
  • 72
BalaB
  • 3,687
  • 9
  • 36
  • 58

1 Answers1

7

You could create a Set and use it as function like this:

val specialChars = Set('*', '@', '&', '=')

val content = "bala.ba* muthu.t@ jiang.xin="
val res = content filterNot specialChars
// bala.ba muthu.t jiang.xin
senia
  • 37,745
  • 4
  • 88
  • 129