I'm new to Scala and for practice I'm trying to write brute-force string matching function that can return a list of indices of matches. The best that I have is pasted below. I would appreciate assitance in making this idiomatic. Also as you'll notice this just prints the indices, whereas I'd prefer a List or Stream.
def strMatching(txt: String, pat: String): Unit = {
val N = txt.length
val M = pat.length
for (i <- 1 to N-M) {
var j = 0
while (j < M && pat(j) == txt(i+j)) {
if (j == M-1) print(s"${i+1} ")
j = j + 1
}
}
}
Thanks a lot!