title: Find index of Nth instance of substring in string in Swift
body: <p>My Swift app involves searching through text in a UITextView. The user can search for a certain substring within that text view, then jump to any instance of that string in the text view (say, the third instance). I need to find out the integer value of which character they are on.</p>
  
  <p>For example:</p>
  
  <p><strong>Example 1:</strong> The user searches for "hello" and the text view reads "hey hi hello, hey hi hello", then the user presses down arrow to view second instance. I need to know the integer value of the first <code>h</code> in the second hello (i.e. which # character that h in hello is within the text view). The integer value should be <code>22</code>.</p>
  
  <p><strong>Example 2:</strong> The user searches for "abc" while the text view reads "abcd" and they are looking for the first instance of <code>abc</code>, so the integer value should be <code>1</code> (which is the integer value of that <code>a</code> since it's the first character of the instance they're searching for).</p>
  
  <p>How can I get the index of the character the user is searching for?</p>