Removing multiple character types from a string

前端 未结 2 970
攒了一身酷
攒了一身酷 2020-12-30 03:39

Is this an acceptable approach for removing multiple character types from a string or is there a better (more efficient way)? The \"ilr\".contains(_) bit feels

2条回答
  •  误落风尘
    2020-12-30 04:10

    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)
    

提交回复
热议问题