I have been looking around for some time now and am wondering how to detect multiple locations of a substring within a larger string. For example:
let text = "Hello, playground. Hello, playground"
let range: Range<String.Index> = text.rangeOfString("playground")! //outputs 7...<17
let index: Int = text.startIndex.distanceTo(range.startIndex) //outputs 7, the location of the first "playground"
I use this code to detect the first location that the substring appears within a string, but its it possible to detect the location of the second occurrence of "playground" and then the third and so on and so forth?