title: How to check what a String starts with (prefix) or ends with (suffix) in Swift
body: <p>I'm trying to test if a Swift string starts or ends with a certain value. These methods do not exist:</p>
  
  <pre><code>var str = "Hello, playground"
  str.startsWith("Hello") // error
  str.endsWith("ground") // error
  </code></pre>
  
  <p>I would also like to get the prefix and suffix strings. I could find a substring, as is answered <a href="https://stackoverflow.com/questions/24044851/how-do-you-use-string-substringwithrange-or-how-do-ranges-work-in-swift">here</a> and <a href="https://stackoverflow.com/questions/28182441/swift-how-to-get-substring-from-start-to-last-index-of-character">here</a>, but ranges are such a pain in Swift.</p>
  
  <p>Is there an easier way to do it?</p>
  
  <p><em>(I stumbled across the answer when I was reading <a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html" rel="noreferrer">the documentation</a>, and since an SO answer didn't come up for my search terms, I am adding my Q&amp;A here.)</em></p>