How to filter of those special char from a word?

683 Views Asked by At

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...

1

There are 1 best solutions below

1
senia On BEST ANSWER

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