title: Substrings in Swift
body: <p>I'm having a problem with understand how I can work with substrings in Swift. Basically, I'm getting a JSON value that has a string with the following format:</p>
  
  <pre><code>&lt;a href="#"&gt;Something&lt;/a&gt;
  </code></pre>
  
  <p>I'm trying to get rid of the HTML anchor tag with Swift so I'm left with <code>Something</code>. My thought was to find the index of every <code>&lt;</code> and <code>&gt;</code> in the string so then I could just do a substringWithRange and advance up to the right index.</p>
  
  <p>My problem is that I can't figure out how to find the index. I've read that Swift doesn't support the index (unless you extend it.)</p>
  
  <p>I don't want to add CPU cycles unnecessarily. So my question is, how do I find the indexes in a way that is not inefficient? Or, is there a better way of filtering out the tags?</p>
  
  <p><strong>Edit:</strong> Converted Andrew's first code sample to a function:</p>
  
  <pre><code>func formatTwitterSource(rawStr: String) -&gt; String {
      let unParsedString = rawStr
      var midParseString = ""
      var parsedString = ""
  
      if let firstEndIndex = find(unParsedString, "&gt;") {
          midParseString = unParsedString[Range&lt;String.Index&gt;(start: firstEndIndex.successor(), end: unParsedString.endIndex)]
          if let secondStartIndex = find(midParseString, "&lt;") {
              parsedString = midParseString[Range&lt;String.Index&gt;(start: midParseString.startIndex, end: secondStartIndex)]
          }
      }          
      return parsedString
  }
  </code></pre>
  
  <p>Nothing too complicated. It takes in a String that has the tags in it. Then it uses Andrew's magic to parse everything out. I renamed the variables and made them clearer so you can see which variable does what in the process. Then in the end, it returns the parsed string.</p>