I want to count the number of tokens in a string with occasional delimiter duplicates. String.split() doesn't work well in this case because it doesn't deduplicate delimiters. For example:
val msg = "The cat won't stay away from the chickens."
val tokens = msg.split(' ')
var count = 0
for(t in tokens)
if(t != "") count++
tokens = ["The", "", "cat", "won't", "", "stay", "", "", "away", "", "from", "", "the", "chickens."]
tokens.size = 14
count = 8
I'm looking for a simpler way to get to the count of 8 in this example. Maybe there's a regex way.