title: Swift Type 'string.index' has no subscript members
body: <p>I'm currently converting C++ code to Swift and I've gotten stuck on one part.  The parameter passed into the function is a string and the area where I'm stuck is when attempting to set a variable based on the second to last character of a string to check for a certain character.</p>
  
  <p>The error shows up on this line:</p>
  
  <pre><code>line[i-1]
  </code></pre>
  
  <p>I've tried casting this value to an Int but this didn't work:</p>
  
  <pre><code>Int(line[i - 1])
  </code></pre>
  
  <p>I've also tried to see if the string's startIndex function which takes a Int would work but it didn't:</p>
  
  <pre><code>line.startIndex[i - 1]
  </code></pre>
  
  <p>Here is the full function: </p>
  
  <pre><code>func scanStringForSpecificCharacters(line: String){
  
      var maxOpen: Int = 0;
      var minOpen: Int = 0;
  
      minOpen = 0;
      maxOpen = 0;
      var i = 0
      while i &lt; line.characters.count {
          for character in line.characters {
  
              //var c: Character = line[i];
              if character == "(" {
                  maxOpen += 1;
                  if i == 0 || line[i - 1] != ":" {
                      minOpen += 1;
                  }
              }
              else if character == ")"{
                  minOpen = max(0,minOpen-1);
                  if i == 0 || line[i-1] != ":"{
                      maxOpen -= 1;
                  }
                  if maxOpen &lt; 0{
                      break;
                  }
              }
          }
  
          if maxOpen &gt;= 0 &amp;&amp; minOpen == 0{
              print("YES")
          }else{
              print("NO")
          }
      }
  }
  </code></pre>