chervak.av
11/29/2019, 6:55 PMvar regWord = word.toRegex
var list = line.split(Regex("""^(regWord)+"""))
i need to count regWord in linekarelpeeters
11/29/2019, 7:52 PMchervak.av
11/29/2019, 8:12 PMlist
, it stores `word`s, the number of which I need to count in a line.
I select one of the `word`s (it may be part of it as "DIFFERENT" and "ent") and after using split
I delete everything except these `word`s. then I count their number. maybe this can be done through find
I do not have text
or `line`s on input, they are randomly generated
mapOf("DIFFERENT" to 2, "ent" to 2, "Sloppy" to 1, "z" to 49, "evolution" to 0)
karelpeeters
11/30/2019, 2:03 PMchervak.av
11/30/2019, 2:59 PMkarelpeeters
11/30/2019, 3:14 PMval string = "abcbcc"
val words = listOf("a", "b", "c")
val result = words.associateWith { word ->
generateSequence(0) { i -> string.indexOf(word, startIndex = i + 1).takeIf { it != -1 } }.count() - 1
}
println(result)
works though.