Scala : How to split words using multiple delimeters
问题 Suppose I have the text file like this: Apple#mango&banana@grapes The data needs to be split on multiple delimiters before performing the word count. How to do that? 回答1: Use split method: scala> "Apple#mango&banana@grapes".split("[#&@]") res0: Array[String] = Array(Apple, mango, banana, grapes) 回答2: If you just want to count words, you don't need to split. Something like this will do: val numWords = """\b\w""".r.findAllIn(string).length This is a regex that matches start of a word ( \b is a