Suppose I have a pretty long string longString and a much shorter substring substring. I want to find the index of the first character for the nth occurrence of substring in longString. In other words, suppose substring = "stackoverflow", and I want to find the nth occurrence of "stackoverflow" in longString, and find the index of the first character of substring (which is the letter s).
Example:
longString = "stackoverflow_is_stackoverflow_not_stackoverflow_even_though_stackoverflow"
substring = "stackoverflow"
n = 2
Thus, in the above example, the index of the s in the 2nd occurrence of "stackoverflow" is 17.
I would like to find an efficient and fast way of doing so.