title: How does String.Index work in Swift
body: <p>I've been updating some of my old code and answers with Swift 3 but when I got to Swift Strings and Indexing it has been a pain to understand things. </p>
  
  <p>Specifically I was trying the following:</p>
  
  <pre><code>let str = "Hello, playground"
  let prefixRange = str.startIndex..&lt;str.startIndex.advancedBy(5) // error
  </code></pre>
  
  <p>where the second line was giving me the following error</p>
  
  <blockquote>
    <p>'advancedBy' is unavailable: To advance an index by n steps call 'index(_:offsetBy:)' on the CharacterView instance that produced the index.</p>
  </blockquote>
  
  <p>I see that <code>String</code> has the following methods.</p>
  
  <pre><code>str.index(after: String.Index)
  str.index(before: String.Index)
  str.index(String.Index, offsetBy: String.IndexDistance)
  str.index(String.Index, offsetBy: String.IndexDistance, limitedBy: String.Index)
  </code></pre>
  
  <p>These were really confusing me at first so I started playing around with them until I understood them. I am adding an answer below to show how they are used.</p>